From bf7e84fb3722ba0564be1aa3a2f0f0149b3e9871 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Wed, 31 Jan 2024 23:51:15 +0100 Subject: Allow combining --email option with --password-from-env Signed-off-by: Herman van Rink --- core/Command/User/Add.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'core/Command/User') 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('--password-from-env given, but OC_PASS is empty!'); - 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( 'The given E-Mail address "%s" is invalid', - $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('--password-from-env given, but OC_PASS is empty!'); + 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 { -- cgit v1.2.3