38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Domain\Identity\AssignStaffRoles;
|
|
use App\Domain\Identity\RegisterAccount;
|
|
use App\Domain\Identity\StaffRole;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Str;
|
|
|
|
class CreateStaffUser extends Command
|
|
{
|
|
protected $signature = 'luf:personal {email} {--role=systemverwalter} {--name=Personal}';
|
|
|
|
protected $description = 'Legt ein bestätigtes Personalkonto an und gibt das Passwort einmal aus';
|
|
|
|
public function handle(RegisterAccount $register, AssignStaffRoles $assign): int
|
|
{
|
|
$role = StaffRole::tryFrom((string) $this->option('role'));
|
|
|
|
if ($role === null) {
|
|
$this->error('Unbekannte Rolle.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$password = Str::password(20);
|
|
$user = $register->register((string) $this->option('name'), (string) $this->argument('email'), $password, true);
|
|
$user->markEmailAsVerified();
|
|
$assign->sync($user, [$role->value], $user);
|
|
|
|
$this->info('Konto angelegt. Passwort (nur diese Ausgabe):');
|
|
$this->line($password);
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|