X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialChangePassword.php;h=91ac4e041e96e19359f9b0ccc483cd6d9c005f46;hb=28c98539cd0fd4a1cf5e9ce7662b7a360fb64dbb;hp=df68b12c3c43f9849a1f12dadfbde5e608787714;hpb=fc8ff5951e102fe697d2ba7b5047fb0b0459ee80;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialChangePassword.php b/includes/specials/SpecialChangePassword.php index df68b12c3c..91ac4e041e 100644 --- a/includes/specials/SpecialChangePassword.php +++ b/includes/specials/SpecialChangePassword.php @@ -190,20 +190,16 @@ class SpecialChangePassword extends FormSpecialPage { return true; } - try { - $this->mUserName = $request->getVal( 'wpName', $this->getUser()->getName() ); - $this->mDomain = $wgAuth->getDomain(); + $this->mUserName = $request->getVal( 'wpName', $this->getUser()->getName() ); + $this->mDomain = $wgAuth->getDomain(); - if ( !$wgAuth->allowPasswordChange() ) { - throw new ErrorPageError( 'changepassword', 'resetpass_forbidden' ); - } + if ( !$wgAuth->allowPasswordChange() ) { + throw new ErrorPageError( 'changepassword', 'resetpass_forbidden' ); + } - $this->attemptReset( $data['Password'], $data['NewPassword'], $data['Retype'] ); + $status = $this->attemptReset( $data['Password'], $data['NewPassword'], $data['Retype'] ); - return true; - } catch ( PasswordError $e ) { - return $e->getMessage(); - } + return $status; } public function onSuccess() { @@ -231,10 +227,14 @@ class SpecialChangePassword extends FormSpecialPage { } /** - * @param string $oldpass - * @param string $newpass - * @param string $retype - * @throws PasswordError When cannot set the new password because requirements not met. + * Checks the new password if it meets the requirements for passwords and set + * it as a current password, otherwise set the passed Status object to fatal + * and doesn't change anything + * + * @param string $oldpass The current (temporary) password. + * @param string $newpass The password to set. + * @param string $retype The string of the retype password field to check with newpass + * @return Status */ protected function attemptReset( $oldpass, $newpass, $retype ) { $isSelf = ( $this->mUserName === $this->getUser()->getName() ); @@ -245,33 +245,32 @@ class SpecialChangePassword extends FormSpecialPage { } if ( !$user || $user->isAnon() ) { - throw new PasswordError( $this->msg( 'nosuchusershort', $this->mUserName )->text() ); + return Status::newFatal( $this->msg( 'nosuchusershort', $this->mUserName ) ); } if ( $newpass !== $retype ) { Hooks::run( 'PrefsPasswordAudit', array( $user, $newpass, 'badretype' ) ); - throw new PasswordError( $this->msg( 'badretype' )->text() ); + return Status::newFatal( $this->msg( 'badretype' ) ); } $throttleCount = LoginForm::incLoginThrottle( $this->mUserName ); if ( $throttleCount === true ) { $lang = $this->getLanguage(); $throttleInfo = $this->getConfig()->get( 'PasswordAttemptThrottle' ); - throw new PasswordError( $this->msg( 'changepassword-throttled' ) + return Status::newFatal( $this->msg( 'changepassword-throttled' ) ->params( $lang->formatDuration( $throttleInfo['seconds'] ) ) - ->text() ); } // @todo Make these separate messages, since the message is written for both cases if ( !$user->checkTemporaryPassword( $oldpass ) && !$user->checkPassword( $oldpass ) ) { Hooks::run( 'PrefsPasswordAudit', array( $user, $newpass, 'wrongpassword' ) ); - throw new PasswordError( $this->msg( 'resetpass-wrong-oldpass' )->text() ); + return Status::newFatal( $this->msg( 'resetpass-wrong-oldpass' ) ); } // User is resetting their password to their old password if ( $oldpass === $newpass ) { - throw new PasswordError( $this->msg( 'resetpass-recycled' )->text() ); + return Status::newFatal( $this->msg( 'resetpass-recycled' ) ); } // Do AbortChangePassword after checking mOldpass, so we don't leak information @@ -279,7 +278,7 @@ class SpecialChangePassword extends FormSpecialPage { $abortMsg = 'resetpass-abort-generic'; if ( !Hooks::run( 'AbortChangePassword', array( $user, $oldpass, $newpass, &$abortMsg ) ) ) { Hooks::run( 'PrefsPasswordAudit', array( $user, $newpass, 'abortreset' ) ); - throw new PasswordError( $this->msg( $abortMsg )->text() ); + return Status::newFatal( $this->msg( $abortMsg ) ); } // Please reset throttle for successful logins, thanks! @@ -292,7 +291,7 @@ class SpecialChangePassword extends FormSpecialPage { Hooks::run( 'PrefsPasswordAudit', array( $user, $newpass, 'success' ) ); } catch ( PasswordError $e ) { Hooks::run( 'PrefsPasswordAudit', array( $user, $newpass, 'error' ) ); - throw new PasswordError( $e->getMessage() ); + return Status::newFatal( new RawMessage( $e->getMessage() ) ); } if ( $isSelf ) { @@ -303,6 +302,7 @@ class SpecialChangePassword extends FormSpecialPage { } $user->saveSettings(); $this->resetPasswordExpiration( $user ); + return Status::newGood(); } public function requiresUnblock() { @@ -336,4 +336,8 @@ class SpecialChangePassword extends FormSpecialPage { __METHOD__ ); } + + protected function getDisplayFormat() { + return 'ooui'; + } }