Piwik\Plugins\Login\PasswordResetter::initiatePasswordResetProcess PHP Method

initiatePasswordResetProcess() public method

The email confirmation link will contain the generated reset token.
public initiatePasswordResetProcess ( string $loginOrEmail, string $newPassword )
$loginOrEmail string The user's login or email address.
$newPassword string The un-hashed/unencrypted password.
    public function initiatePasswordResetProcess($loginOrEmail, $newPassword)
    {
        $this->checkNewPassword($newPassword);
        // 'anonymous' has no password and cannot be reset
        if ($loginOrEmail === 'anonymous') {
            throw new Exception(Piwik::translate('Login_InvalidUsernameEmail'));
        }
        // get the user's login
        $user = $this->getUserInformation($loginOrEmail);
        if ($user === null) {
            throw new Exception(Piwik::translate('Login_InvalidUsernameEmail'));
        }
        $login = $user['login'];
        $this->savePasswordResetInfo($login, $newPassword);
        // ... send email with confirmation link
        try {
            $this->sendEmailConfirmationLink($user);
        } catch (Exception $ex) {
            // remove password reset info
            $this->removePasswordResetInfo($login);
            throw new Exception($ex->getMessage() . Piwik::translate('Login_ContactAdmin'));
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Saves password reset info and sends confirmation email.
  *
  * @param QuickForm2 $form
  * @return array Error message(s) if an error occurs.
  */
 protected function resetPasswordFirstStep($form)
 {
     $loginMail = $form->getSubmitValue('form_login');
     $password = $form->getSubmitValue('form_password');
     try {
         $this->passwordResetter->initiatePasswordResetProcess($loginMail, $password);
     } catch (Exception $ex) {
         Log::debug($ex);
         return array($ex->getMessage());
     }
     return null;
 }