diff --git a/changelog/unreleased/36925 b/changelog/unreleased/36925 new file mode 100644 index 000000000000..e25b953f76f6 --- /dev/null +++ b/changelog/unreleased/36925 @@ -0,0 +1,13 @@ +Bugfix: user:resetpassword with --send-email --password-from-env + +When trying to do command: +occ user:resetpassword Anne --send-email --password-from-env + +If Anne does not have an email address setup then an error was logged in the +ownCloud log. + +This has been corrected. Now the administrator is shown the correct error +"Email address is not set for the user Anne" + +https://github.com/owncloud/core/issues/36925 +https://github.com/owncloud/core/pull/36926 diff --git a/core/Command/User/ResetPassword.php b/core/Command/User/ResetPassword.php index 0ae095e5ae99..aa56186793b8 100644 --- a/core/Command/User/ResetPassword.php +++ b/core/Command/User/ResetPassword.php @@ -179,6 +179,10 @@ protected function execute(InputInterface $input, OutputInterface $output) { if ($emailLink) { $userId = $user->getUID(); list(, $token) = $this->lostController->generateTokenAndLink($userId); + if (!$this->hasValidEmailAddress($user->getEMailAddress())) { + $output->writeln('Email address is not set for the user ' . $user->getUID() . ''); + return 1; + } $this->config->setUserValue($userId, 'owncloud', 'lostpassword', $this->timeFactory->getTime() . ':' . $token); $success = $this->lostController->setPassword($token, $userId, $password, false); if (\is_array($success) && isset($success['status']) && $success['status'] === 'success') { diff --git a/tests/acceptance/features/cliProvisioning/resetUserPassword.feature b/tests/acceptance/features/cliProvisioning/resetUserPassword.feature index 2b1cc2723791..5f09c4933ed5 100644 --- a/tests/acceptance/features/cliProvisioning/resetUserPassword.feature +++ b/tests/acceptance/features/cliProvisioning/resetUserPassword.feature @@ -48,15 +48,13 @@ Feature: reset user password Then the command should have failed with exit code 1 And the command output should contain the text "Email address is not set for the user brand-new-user" - @issue-36925 Scenario: administrator gets error message while trying to reset specifying user password with send email when the email address of the user is not setup Given these users have been created with skeleton files: | username | password | displayname | | brand-new-user | %regular% | New user | When the administrator resets the password of user "brand-new-user" to "%alt1%" sending email using the occ command Then the command should have failed with exit code 1 - And the command output should contain the text "Error while resetting password!" - #And the command output should contain the text "Email address is not set for the user brand-new-user" + And the command output should contain the text "Email address is not set for the user brand-new-user" Scenario: user should not get an email when the smtpmode value points to an invalid or missing mail program Given these users have been created with skeleton files: