-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
* Add prompt to create admin user * fix code formatting --------- Co-authored-by: mckenziearts <[email protected]>
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,10 @@ | |
use Illuminate\Support\Facades\Hash; | ||
use Shopper\Core\Models\User; | ||
|
||
use function Laravel\Prompts\info; | ||
Check failure on line 13 in packages/admin/src/Console/UserCommand.php GitHub Actions / P8.2 - L9.* - prefer-stable
|
||
use function Laravel\Prompts\password; | ||
Check failure on line 14 in packages/admin/src/Console/UserCommand.php GitHub Actions / P8.2 - L9.* - prefer-stable
|
||
use function Laravel\Prompts\text; | ||
Check failure on line 15 in packages/admin/src/Console/UserCommand.php GitHub Actions / P8.2 - L9.* - prefer-stable
|
||
|
||
final class UserCommand extends Command | ||
{ | ||
protected $signature = 'shopper:admin'; | ||
|
@@ -18,24 +22,42 @@ final class UserCommand extends Command | |
|
||
public function handle(): void | ||
{ | ||
$this->info('Create Admin User for Shopper administration panel'); | ||
info('Create Admin User for Shopper administration panel'); | ||
Check failure on line 25 in packages/admin/src/Console/UserCommand.php GitHub Actions / P8.2 - L9.* - prefer-stable
|
||
$this->createUser(); | ||
$this->info('User created successfully.'); | ||
info('User created successfully.'); | ||
Check failure on line 27 in packages/admin/src/Console/UserCommand.php GitHub Actions / P8.2 - L9.* - prefer-stable
|
||
} | ||
|
||
protected function createUser(): void | ||
{ | ||
$email = $this->ask('Email Address', '[email protected]'); | ||
$first_name = $this->ask('First Name', 'Shopper'); | ||
$last_name = $this->ask('Last Name', 'User'); | ||
$password = $this->secret('Password'); | ||
$confirmPassword = $this->secret('Confirm Password'); | ||
|
||
if ($password !== $confirmPassword) { | ||
$this->info('Passwords don\'t match'); | ||
} | ||
$email = text( | ||
Check failure on line 32 in packages/admin/src/Console/UserCommand.php GitHub Actions / P8.2 - L9.* - prefer-stable
|
||
label: 'Your Email Address', | ||
default: '[email protected]', | ||
required: true, | ||
validate: fn (string $value) => User::where('email', $value)->exists() | ||
? 'An admin with that email already exists.' | ||
: null, | ||
); | ||
$first_name = text( | ||
Check failure on line 40 in packages/admin/src/Console/UserCommand.php GitHub Actions / P8.2 - L9.* - prefer-stable
|
||
label: 'What is your First Name', | ||
default: 'Shopper', | ||
required: true, | ||
); | ||
$last_name = text( | ||
Check failure on line 45 in packages/admin/src/Console/UserCommand.php GitHub Actions / P8.2 - L9.* - prefer-stable
|
||
label: 'What is your Last Name', | ||
default: 'User', | ||
required: true, | ||
); | ||
$password = password( | ||
Check failure on line 50 in packages/admin/src/Console/UserCommand.php GitHub Actions / P8.2 - L9.* - prefer-stable
|
||
label: 'Choose a Password', | ||
required: true, | ||
validate: fn (string $value) => match (true) { | ||
mb_strlen($value) < 6 => 'The password must be at least 6 characters.', | ||
default => null | ||
}, | ||
hint: 'Minimum 6 characters.' | ||
); | ||
|
||
$this->info('Creating admin account...'); | ||
info('Creating admin account...'); | ||
|
||
$userData = [ | ||
'email' => $email, | ||
|