update manifest, install; add CreateUser.php to preseed admin during install
This commit is contained in:
parent
18ea4071c7
commit
418c941db9
1 changed files with 63 additions and 0 deletions
63
conf/CreateUser.php
Normal file
63
conf/CreateUser.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class CreateUser extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:create-user
|
||||
{name : The username of the user}
|
||||
{email : The email of the user}
|
||||
{password : Password in plain text (will be encrypted automatically)}
|
||||
{--unverified : Keep the user unverified. Otherwise, email verified will be set at current time.}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a user to access the admin panel';
|
||||
|
||||
private array $rules = [
|
||||
'name' => ['required', 'min:4', 'unique:users,name'],
|
||||
'email' => ['required', 'email', 'unique:users,email'],
|
||||
'password' => ['required', 'min:6'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$validator = Validator::make([
|
||||
'name' => $this->argument('name'),
|
||||
'email' => $this->argument('email'),
|
||||
'password' => $this->argument('password'),
|
||||
], $this->rules);
|
||||
|
||||
try {
|
||||
$userData = $validator->validated();
|
||||
|
||||
$userData['password'] = bcrypt($userData['password']);
|
||||
$userData['email_verified_at'] = $this->option('unverified') ? NULL : now();
|
||||
|
||||
User::factory()->create($userData);
|
||||
|
||||
$this->info('User created.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error("ERROR: {$e->getMessage()} [Code: {$e->getCode()}]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue