60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Str;
|
|
|
|
class CreateAdmin extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'admin:create';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Create or reset admin user admin@citrus.com with a random password';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
$email = 'admin@citrus.com';
|
|
$password = Str::random(12);
|
|
|
|
$user = User::where('email', $email)->first();
|
|
|
|
if ($user) {
|
|
$user->password = Hash::make($password);
|
|
$user->level = 'Admin';
|
|
$user->save();
|
|
$status = 'updated';
|
|
} else {
|
|
$user = new User();
|
|
$user->name = 'Admin';
|
|
$user->email = $email;
|
|
$user->password = Hash::make($password);
|
|
$user->level = 'Admin';
|
|
$user->save();
|
|
$status = 'created';
|
|
}
|
|
|
|
$this->info("Admin user has been {$status}.");
|
|
$this->line("--------------------------------");
|
|
$this->info("Email: {$email}");
|
|
$this->info("Password: {$password}");
|
|
$this->line("--------------------------------");
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|