From 36c37e0c62d8865c0a44cced92976a3f84fcb174 Mon Sep 17 00:00:00 2001 From: Matthew Exon Date: Sun, 14 Jan 2024 16:19:20 +0100 Subject: [PATCH] Allow setting user avatar in the console at creation --- src/Console/User.php | 18 ++++++++++++------ src/Model/User.php | 14 ++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Console/User.php b/src/Console/User.php index 0c2f17eb3c..e175c54477 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -58,7 +58,7 @@ class User extends \Asika\SimpleConsole\Console console user - Modify user settings per console commands. Usage bin/console user password [] [-h|--help|-?] [-v] - bin/console user add [ [ [ []]]] [-h|--help|-?] [-v] + bin/console user add [ [ [ [ []]]]] [-h|--help|-?] [-v] bin/console user delete [] [-y] [-h|--help|-?] [-v] bin/console user allow [] [-h|--help|-?] [-v] bin/console user deny [] [-h|--help|-?] [-v] @@ -228,10 +228,11 @@ HELP; */ private function addUser() { - $name = $this->getArgument(1); - $nick = $this->getArgument(2); - $email = $this->getArgument(3); - $lang = $this->getArgument(4); + $name = $this->getArgument(1); + $nick = $this->getArgument(2); + $email = $this->getArgument(3); + $lang = $this->getArgument(4); + $avatar = $this->getArgument(5); if (empty($name)) { $this->out($this->l10n->t('Enter user name: ')); @@ -262,10 +263,15 @@ HELP; $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)) { return UserModel::createMinimal($name, $email, $nick); } else { - return UserModel::createMinimal($name, $email, $nick, $lang); + return UserModel::createMinimal($name, $email, $nick, $lang, $avatar); } } diff --git a/src/Model/User.php b/src/Model/User.php index 2a8ce5330d..9ae434e0b5 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -1553,16 +1553,17 @@ class User /** * Creates a new user based on a minimal set and sends an email to this user * - * @param string $name The user's name - * @param string $email The user's email address - * @param string $nick The user's nick name - * @param string $lang The user's language (default is english) + * @param string $name The user's name + * @param string $email The user's email address + * @param string $nick The user's nick name + * @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 * @throws HTTPException\InternalServerErrorException * @throws ErrorException * @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) || empty($email) || @@ -1575,7 +1576,8 @@ class User 'email' => $email, 'nickname' => $nick, 'verified' => 1, - 'language' => $lang + 'language' => $lang, + 'photo' => $avatar ]); $user = $result['user']; -- 2.39.5