-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
]; |