35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Console\Attributes\Description;
|
|
use Illuminate\Console\Attributes\Signature;
|
|
use Illuminate\Console\Command;
|
|
|
|
#[Signature('app:create-admin {username} {email}')]
|
|
#[Description('Create the first HickLab3D administrator')]
|
|
class CreateAdmin extends Command
|
|
{
|
|
public function handle(): int
|
|
{
|
|
$username = (string) $this->argument('username');
|
|
$email = (string) $this->argument('email');
|
|
if (User::where('username', $username)->orWhere('email', $email)->exists()) {
|
|
$this->error('That username or email already exists.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
$password = (string) $this->secret('Password (at least 12 characters)');
|
|
if (mb_strlen($password) < 12) {
|
|
$this->error('Password is too short.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
User::create(['username' => $username, 'email' => $email, 'role' => 'admin', 'password' => $password]);
|
|
$this->info('Administrator created.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|