Skip to content

Commit

Permalink
New make:user command
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed Feb 24, 2024
1 parent 6430c1f commit 34f4b97
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions commands/make/user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types = 1);

use Kirby\CLI\CLI;
use Kirby\Cms\User;

return [
'description' => '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());
}
];

0 comments on commit 34f4b97

Please sign in to comment.