UserManager::activatePassword PHP Method

activatePassword() public method

public activatePassword ( $token, null $password = null, boolean | true $notify = true ) : boolean
$token
$password null
$notify boolean | true
return boolean
    public function activatePassword($token, $password = null, $notify = true)
    {
        $tokenModel = $this->tokenStorage->get($token, UserToken::TYPE_CHANGE_PASSWORD);
        if (null === $tokenModel) {
            Yii::app()->eventManager->fire(UserEvents::FAILURE_ACTIVATE_PASSWORD, new UserActivatePasswordEvent($token));
            return false;
        }
        $userModel = User::model()->active()->findByPk($tokenModel->user_id);
        if (null === $userModel) {
            Yii::app()->eventManager->fire(UserEvents::FAILURE_ACTIVATE_PASSWORD, new UserActivatePasswordEvent($token));
            return false;
        }
        $transaction = Yii::app()->getDb()->beginTransaction();
        try {
            if (null === $password) {
                $password = $this->hasher->generateRandomPassword();
            }
            if ($this->changeUserPassword($userModel, $password) && $this->tokenStorage->activate($tokenModel)) {
                Yii::app()->eventManager->fire(UserEvents::SUCCESS_ACTIVATE_PASSWORD, new UserActivatePasswordEvent($token, $password, $userModel, $notify));
                $transaction->commit();
                return true;
            }
            throw new CException(Yii::t('UserModule.user', 'Error generating new password!'));
        } catch (Exception $e) {
            $transaction->rollback();
            return false;
        }
    }