public function passwordRecovery($email)
{
Yii::app()->eventManager->fire(UserEvents::BEFORE_PASSWORD_RECOVERY, new UserPasswordRecoveryEvent($email));
if (!$email) {
return false;
}
$user = User::model()->active()->find('email = :email', [':email' => $email]);
if (null === $user) {
return false;
}
$transaction = Yii::app()->getDb()->beginTransaction();
try {
if (($token = $this->tokenStorage->createPasswordRecoveryToken($user)) !== false) {
Yii::app()->eventManager->fire(UserEvents::SUCCESS_PASSWORD_RECOVERY, new UserPasswordRecoveryEvent($email, $user, $token));
$transaction->commit();
return true;
}
throw new CException(Yii::t('UserModule.user', 'Password recovery error.'));
} catch (Exception $e) {
$transaction->rollback();
Yii::app()->eventManager->fire(UserEvents::FAILURE_PASSWORD_RECOVERY, new UserPasswordRecoveryEvent($email, $user));
return false;
}
}