Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PasswordRecoveryService to check if the user exist before send… #411

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/User/Service/PasswordRecoveryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,13 @@ public function __construct($email, MailService $mailService, UserQuery $query)
public function run()
{
try {
if ($this->getModule()->enableFlashMessages == true) {
Yii::$app->session->setFlash(
'info',
Yii::t('usuario', 'An email with instructions to create a new password has been sent to {email} if it is associated with an {appName} account. Your existing password has not been changed.', ['email' => $this->email, 'appName' => Yii::$app->name])
);
}

/** @var User $user */
$user = $this->query->whereEmail($this->email)->one();

if ($user === null) {
throw new \RuntimeException('User not found.');
Yii::$app->session->setFlash('error', Yii::t('usuario', 'User not found.'));
return false;
}

$token = TokenFactory::makeRecoveryToken($user->id);
Expand All @@ -67,6 +62,12 @@ public function run()
return false;
}

if ($this->getModule()->enableFlashMessages == true) {
Yii::$app->session->setFlash(
'info',
Yii::t('usuario', 'An email with instructions to create a new password has been sent to {email} if it is associated with an {appName} account. Your existing password has not been changed.', ['email' => $this->email, 'appName' => Yii::$app->name])
);
}
return true;
} catch (Exception $e) {
Yii::error($e->getMessage(), 'usuario');
Expand Down