diff --git a/README.md b/README.md index 530ae53..f73a2a4 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ This should print the Kirby CLI version and a list of available commands - kirby make:plugin - kirby make:snippet - kirby make:template +- kirby make:user - kirby register - kirby remove:command - kirby roots diff --git a/commands/make/user.php b/commands/make/user.php new file mode 100644 index 0000000..9c95f70 --- /dev/null +++ b/commands/make/user.php @@ -0,0 +1,53 @@ + 'Creates a new user', + 'args' => [ + 'email' => [ + 'description' => 'The email of the user' + ], + 'role' => [ + 'description' => 'The role of the user' + ], + 'name' => [ + 'description' => 'The name of the user' + ], + 'language' => [ + 'description' => 'The language of the user', + ], + 'password' => [ + 'description' => 'The password of the user' + ] + ], + 'command' => static function (CLI $cli): void { + $kirby = $cli->kirby(); + $email = $cli->argOrPrompt('email', 'Enter an email:'); + $role = $cli->radio('Select a user role:', $kirby->roles()->pluck('id'))->prompt(); + $name = $cli->argOrPrompt('name', 'Enter a name (optional):', false); + $language = $cli->argOrPrompt('language', 'Enter a language code (Leave empty to use default EN):', false); + $password = $cli->argOrPrompt('password', 'Enter a password (Leave empty for the passwordless login):', false); + + $data = [ + 'email' => $email, + 'name' => $name, + 'role' => $role, + 'language' => empty($language) === false ? strtolower($language) : 'en' + ]; + + if (empty($password) === false) { + $data['password'] = $password; + } + + // authenticate as almighty + $kirby->impersonate('kirby'); + + $user = User::create($data); + + $cli->success('The user has been created. The new user id: ' . $user->id()); + } +];