/** * @param $token * @param null $password * @param bool|true $notify * @return bool */ 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; } }