diff options
author | Herman van Rink <rink@initfour.nl> | 2024-01-31 23:51:15 +0100 |
---|---|---|
committer | Anupam Kumar <kyteinsky@gmail.com> | 2024-02-24 04:56:52 +0530 |
commit | bf7e84fb3722ba0564be1aa3a2f0f0149b3e9871 (patch) | |
tree | 77207e6c3996582f9ea3b7504efa331e2c271121 /core/Command/User | |
parent | a92c507cb6561f645d4982a5fc48e58c4f0bc27e (diff) | |
download | nextcloud-server-bf7e84fb3722ba0564be1aa3a2f0f0149b3e9871.tar.gz nextcloud-server-bf7e84fb3722ba0564be1aa3a2f0f0149b3e9871.zip |
Allow combining --email option with --password-from-env
Signed-off-by: Herman van Rink <rink@initfour.nl>
Diffstat (limited to 'core/Command/User')
-rw-r--r-- | core/Command/User/Add.php | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/core/Command/User/Add.php b/core/Command/User/Add.php index b179b562d20..b456f636859 100644 --- a/core/Command/User/Add.php +++ b/core/Command/User/Add.php @@ -103,24 +103,27 @@ class Add extends Command { $password = ''; $sendPasswordEmail = false; - if ($input->getOption('password-from-env')) { - $password = getenv('OC_PASS'); - - if (!$password) { - $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); - return 1; - } - } elseif ($input->getOption('email') !== '') { - if (!$this->mailer->validateMailAddress($input->getOption(('email')))) { + $email = $input->getOption('email'); + if (!empty($email)) { + if (!$this->mailer->validateMailAddress($email)) { $output->writeln(\sprintf( '<error>The given E-Mail address "%s" is invalid</error>', - $input->getOption('email'), + $email, )); return 1; } + } - $output->writeln('Setting a temporary password.'); + // Setup password. + if ($input->getOption('password-from-env')) { + $password = getenv('OC_PASS'); + + if (!$password) { + $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); + return 1; + } + } elseif (!empty($email)) { $passwordEvent = new GenerateSecurePasswordEvent(); $this->eventDispatcher->dispatchTyped($passwordEvent); @@ -170,6 +173,10 @@ class Add extends Command { $output->writeln('Display name set to "' . $user->getDisplayName() . '"'); } + if (!empty($email)) { + $user->setSystemEMailAddress($email); + } + $groups = $input->getOption('group'); if (!empty($groups)) { @@ -195,8 +202,6 @@ class Add extends Command { // Send email to user if we set a temporary password if ($sendPasswordEmail) { - $email = $input->getOption('email'); - $user->setSystemEMailAddress($email); if ($this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') { try { |