Skip to content

Commit

Permalink
Add prompt to create admin user (#231)
Browse files Browse the repository at this point in the history
* Add prompt to create admin user

* fix code formatting

---------

Co-authored-by: mckenziearts <[email protected]>
  • Loading branch information
mckenziearts and mckenziearts authored Jan 19, 2024
1 parent 463fb8d commit 73d7747
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"blade-ui-kit/blade-heroicons": "^1.2",
"danharrin/livewire-rate-limiting": "^0.3|^1.0",
"doctrine/dbal": "^3.6",
"larastan/larastan": "^2.0",
"laravel/pint": "^1.1",
"mockery/mockery": "^1.4",
"nunomaduro/collision": "^5.11|^6.1",
"larastan/larastan": "^2.0",
"orchestra/testbench": "^7.0|^8.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.0",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/admin/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"illuminate/view": "^9.0|^10.0",
"jenssegers/agent": "^2.6",
"laravel/helpers": "^1.4.1",
"laravel/prompts": "^0.1.15",
"livewire/livewire": "^2.10",
"maatwebsite/excel": "^3.1",
"mckenziearts/blade-untitledui-icons": "^1.2",
Expand Down
46 changes: 34 additions & 12 deletions packages/admin/src/Console/UserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-stable

Used function Laravel\Prompts\info not found.

Check failure on line 13 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-stable

Used function Laravel\Prompts\info not found.
use function Laravel\Prompts\password;

Check failure on line 14 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-stable

Used function Laravel\Prompts\password not found.

Check failure on line 14 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-stable

Used function Laravel\Prompts\password not found.
use function Laravel\Prompts\text;

Check failure on line 15 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-stable

Used function Laravel\Prompts\text not found.

Check failure on line 15 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-stable

Used function Laravel\Prompts\text not found.

final class UserCommand extends Command
{
protected $signature = 'shopper:admin';
Expand All @@ -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

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-stable

Function Laravel\Prompts\info not found.

Check failure on line 25 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-stable

Function Laravel\Prompts\info not found.
$this->createUser();
$this->info('User created successfully.');
info('User created successfully.');

Check failure on line 27 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-stable

Function Laravel\Prompts\info not found.

Check failure on line 27 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-stable

Function Laravel\Prompts\info not found.
}

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

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-stable

Function Laravel\Prompts\text not found.

Check failure on line 32 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-stable

Function Laravel\Prompts\text not found.
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

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-stable

Function Laravel\Prompts\text not found.

Check failure on line 40 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-stable

Function Laravel\Prompts\text not found.
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

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-stable

Function Laravel\Prompts\text not found.

Check failure on line 45 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-stable

Function Laravel\Prompts\text not found.
label: 'What is your Last Name',
default: 'User',
required: true,
);
$password = password(

Check failure on line 50 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-stable

Function Laravel\Prompts\password not found.

Check failure on line 50 in packages/admin/src/Console/UserCommand.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-stable

Function Laravel\Prompts\password not found.
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,
Expand Down

0 comments on commit 73d7747

Please sign in to comment.