]> source.dussan.org Git - nextcloud-server.git/commitdiff
allow using of disabled password reset mechanism for special cases 28841/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Fri, 10 Sep 2021 20:40:10 +0000 (22:40 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 15 Sep 2021 01:32:44 +0000 (01:32 +0000)
- LostController has three endpoints
- door opener email() still rejects
- resetform(), reachable from mail, checks the token first and may report
  that password reset is disabled
- setPassword() got its check removed as it is behind CSFR anyway and still
  requires a valid token
- this allows special cases like activating a freshly created guest account

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
core/Controller/LostController.php

index dcfb37e84ef89b69ac29c1e73b1bbbbe9bd2ce15..9edc7d0139484a9062db2800ec99828d1fa5f4b1 100644 (file)
@@ -134,22 +134,24 @@ class LostController extends Controller {
         * @return TemplateResponse
         */
        public function resetform($token, $userId) {
-               if ($this->config->getSystemValue('lost_password_link', '') !== '') {
-                       return new TemplateResponse('core', 'error', [
-                               'errors' => [['error' => $this->l10n->t('Password reset is disabled')]]
-                       ],
-                               'guest'
-                       );
-               }
-
                try {
                        $this->checkPasswordResetToken($token, $userId);
                } catch (\Exception $e) {
-                       return new TemplateResponse(
-                               'core', 'error', [
-                                       "errors" => [["error" => $e->getMessage()]]
-                               ],
-                               'guest'
+                       if ($this->config->getSystemValue('lost_password_link', '') !== 'disabled'
+                               || ($e instanceof InvalidTokenException
+                                       && !in_array($e->getCode(), [InvalidTokenException::TOKEN_NOT_FOUND, InvalidTokenException::USER_UNKNOWN]))
+                       ) {
+                               return new TemplateResponse(
+                                       'core', 'error', [
+                                               "errors" => [["error" => $e->getMessage()]]
+                                       ],
+                                       TemplateResponse::RENDER_AS_GUEST
+                               );
+                       }
+                       return new TemplateResponse('core', 'error', [
+                               'errors' => [['error' => $this->l10n->t('Password reset is disabled')]]
+                       ],
+                               TemplateResponse::RENDER_AS_GUEST
                        );
                }
                $this->initialStateService->provideInitialState('core', 'resetPasswordUser', $userId);
@@ -242,10 +244,6 @@ class LostController extends Controller {
         * @return array
         */
        public function setPassword($token, $userId, $password, $proceed) {
-               if ($this->config->getSystemValue('lost_password_link', '') !== '') {
-                       return $this->error($this->l10n->t('Password reset is disabled'));
-               }
-
                if ($this->encryptionManager->isEnabled() && !$proceed) {
                        $encryptionModules = $this->encryptionManager->getEncryptionModules();
                        foreach ($encryptionModules as $module) {