diff --git a/modules/backend/ServiceProvider.php b/modules/backend/ServiceProvider.php index d300988aae..c81552de9d 100644 --- a/modules/backend/ServiceProvider.php +++ b/modules/backend/ServiceProvider.php @@ -55,7 +55,7 @@ protected function registerConsole() $this->registerConsoleCommand('create.controller', \Backend\Console\CreateController::class); $this->registerConsoleCommand('create.formwidget', \Backend\Console\CreateFormWidget::class); $this->registerConsoleCommand('create.reportwidget', \Backend\Console\CreateReportWidget::class); - + $this->registerConsoleCommand('user.create', \Backend\Console\UserCreate::class); $this->registerConsoleCommand('winter.passwd', \Backend\Console\WinterPasswd::class); } diff --git a/modules/backend/classes/Controller.php b/modules/backend/classes/Controller.php index 9139ded692..bb413249fe 100644 --- a/modules/backend/classes/Controller.php +++ b/modules/backend/classes/Controller.php @@ -1,13 +1,13 @@ -Use the role\'s code} + {--f|force : Force the operation to run and ignore production warnings and confirmation questions.}'; + + /** + * @var string The console command description. + */ + protected $description = 'Creates a backend user.'; + + /** + * Execute the console command. + */ + public function handle(): int + { + $email = $this->argument('email'); + + if ( + Config::get('app.env', 'production') !== 'local' + && !$this->option('force') + && !$this->confirmWithInput("CAUTION, currently working with non-local data. Please confirm the user email address", $email) + ) { + return 1; + } + + if (User::where('email', $email)->exists()) { + $this->error('A user with that email already exists.'); + return 1; + } + + $data = [ + 'email' => $email, + 'password' => $this->option('password') ?: $this->secret('Password'), + 'first_name' => $this->option('fname') ?: $this->ask('First name', ''), + 'last_name' => $this->option('lname') ?: $this->ask('Last name', ''), + 'role_id' => ( + $role = UserRole::where( + 'code', + $this->option('role') ?: $this->choice( + 'Role', + UserRole::lists('name', 'code') + ) + )->firstOrFail() + )->id, + ]; + + $data['password_confirmation'] = $data['password']; + + $user = User::create([ + 'first_name' => $data['first_name'], + 'last_name' => $data['last_name'], + 'login' => $data['email'], + 'email' => $data['email'], + 'role_id' => $data['role_id'], + 'password' => $data['password'], + 'password_confirmation' => $data['password'], + ]); + + $this->info("User {$user->email} created successfully with the {$role->name} role."); + + return 0; + } +} diff --git a/modules/backend/layouts/_head.php b/modules/backend/layouts/_head.php index f1b4526c21..0ff93ceb75 100644 --- a/modules/backend/layouts/_head.php +++ b/modules/backend/layouts/_head.php @@ -12,14 +12,18 @@ pageTitle)) ?> | addCss($style, [ + 'build' => 'core', + 'order' => 1, + ]); +} // Scripts $scripts = [ @@ -49,18 +53,14 @@ Backend::skinAsset('assets/js/winter.flyout.js'), Backend::skinAsset('assets/js/winter.tabformexpandcontrols.js'), ]); +foreach ($scripts as $script) { + $this->addJs($script, [ + 'build' => 'core', + 'order' => 1, + ]); +} ?> - - - - - - - - - - - - -