Allow setting user avatar in the console at creation

This commit is contained in:
Matthew Exon 2024-01-14 16:19:20 +01:00
parent 2b8126b780
commit 36c37e0c62
2 changed files with 20 additions and 12 deletions

View file

@ -58,7 +58,7 @@ class User extends \Asika\SimpleConsole\Console
console user - Modify user settings per console commands. console user - Modify user settings per console commands.
Usage Usage
bin/console user password <nickname> [<password>] [-h|--help|-?] [-v] bin/console user password <nickname> [<password>] [-h|--help|-?] [-v]
bin/console user add [<name> [<nickname> [<email> [<language>]]]] [-h|--help|-?] [-v] bin/console user add [<name> [<nickname> [<email> [<language> [<avatar_url>]]]]] [-h|--help|-?] [-v]
bin/console user delete [<nickname>] [-y] [-h|--help|-?] [-v] bin/console user delete [<nickname>] [-y] [-h|--help|-?] [-v]
bin/console user allow [<nickname>] [-h|--help|-?] [-v] bin/console user allow [<nickname>] [-h|--help|-?] [-v]
bin/console user deny [<nickname>] [-h|--help|-?] [-v] bin/console user deny [<nickname>] [-h|--help|-?] [-v]
@ -232,6 +232,7 @@ HELP;
$nick = $this->getArgument(2); $nick = $this->getArgument(2);
$email = $this->getArgument(3); $email = $this->getArgument(3);
$lang = $this->getArgument(4); $lang = $this->getArgument(4);
$avatar = $this->getArgument(5);
if (empty($name)) { if (empty($name)) {
$this->out($this->l10n->t('Enter user name: ')); $this->out($this->l10n->t('Enter user name: '));
@ -262,10 +263,15 @@ HELP;
$lang = CliPrompt::prompt(); $lang = CliPrompt::prompt();
} }
if (empty($avatar)) {
$this->out($this->l10n->t('Enter URL of an image to use as avatar (optional): '));
$avatar = CliPrompt::prompt();
}
if (empty($lang)) { if (empty($lang)) {
return UserModel::createMinimal($name, $email, $nick); return UserModel::createMinimal($name, $email, $nick);
} else { } else {
return UserModel::createMinimal($name, $email, $nick, $lang); return UserModel::createMinimal($name, $email, $nick, $lang, $avatar);
} }
} }

View file

@ -1557,12 +1557,13 @@ class User
* @param string $email The user's email address * @param string $email The user's email address
* @param string $nick The user's nick name * @param string $nick The user's nick name
* @param string $lang The user's language (default is english) * @param string $lang The user's language (default is english)
* @param string $avatar URL to an image to use as avatar (default is to prompt user at first login)
* @return bool True, if the user was created successfully * @return bool True, if the user was created successfully
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
* @throws ErrorException * @throws ErrorException
* @throws ImagickException * @throws ImagickException
*/ */
public static function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT): bool public static function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT, string $avatar = ''): bool
{ {
if (empty($name) || if (empty($name) ||
empty($email) || empty($email) ||
@ -1575,7 +1576,8 @@ class User
'email' => $email, 'email' => $email,
'nickname' => $nick, 'nickname' => $nick,
'verified' => 1, 'verified' => 1,
'language' => $lang 'language' => $lang,
'photo' => $avatar
]); ]);
$user = $result['user']; $user = $result['user'];