Skip to content

Commit

Permalink
bug #785 [Reset-Password] use expiration translation in check email r…
Browse files Browse the repository at this point in the history
…oute (jrushlow)

This PR was squashed before being merged into the 1.0-dev branch.

Discussion
----------

[Reset-Password] use expiration translation in check email route

I missed this template in #770

- [x] Depends on SymfonyCasts/reset-password-bundle#143

Commits
-------

bd1e578 [Reset-Password] use expiration translation in check email route
  • Loading branch information
weaverryan committed Jan 15, 2021
2 parents 1b6861f + bd1e578 commit 6f4d27a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
11 changes: 5 additions & 6 deletions src/Maker/MakeResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Yaml\Yaml;
use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestTrait;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordToken;
Expand Down Expand Up @@ -84,13 +85,11 @@ public function configureDependencies(DependencyBuilder $dependencies)

$dependencies->addClassDependency(Annotation::class, 'annotations');

// reset-password-bundle 1.2.1 includes support for translations and a fix for the bad expiration time bug.
// we need to check that version 1.2.1 is installed
// reset-password-bundle 1.3 includes helpers to get/set a ResetPasswordToken object from the session.
// we need to check that version 1.3 is installed
if (class_exists(ResetPasswordToken::class)) {
$reflectedToken = new \ReflectionClass(ResetPasswordToken::class);

if (!$reflectedToken->hasMethod('getExpirationMessageKey')) {
throw new RuntimeCommandException('Please upgrade symfonycasts/reset-password-bundle to version 1.2.1 or greater.');
if (!method_exists(ResetPasswordControllerTrait::class, 'getTokenObjectFromSession')) {
throw new RuntimeCommandException('Please upgrade symfonycasts/reset-password-bundle to version 1.3 or greater.');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public function request(Request $request, MailerInterface $mailer): Response
public function checkEmail(): Response
{
// We prevent users from directly accessing this page
if (!$this->canCheckEmail()) {
if (null === ($resetToken = $this->getTokenObjectFromSession())) {
return $this->redirectToRoute('app_forgot_password_request');
}

return $this->render('reset_password/check_email.html.twig', [
'tokenLifetime' => $this->resetPasswordHelper->getTokenLifetime(),
'resetToken' => $resetToken,
]);
}

Expand Down Expand Up @@ -155,9 +155,6 @@ private function processSendingPasswordResetEmail(string $emailFormData, MailerI
'<?= $email_field ?>' => $emailFormData,
]);

// Marks that you are allowed to see the app_check_email page.
$this->setCanCheckEmailInSession();

// Do not reveal whether a user account was found or not.
if (!$user) {
return $this->redirectToRoute('app_check_email');
Expand Down Expand Up @@ -190,6 +187,9 @@ private function processSendingPasswordResetEmail(string $emailFormData, MailerI

$mailer->send($email);

// Store the token object in session for retrieval in check-email route.
$this->setTokenObjectInSession($resetToken);

return $this->redirectToRoute('app_check_email');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
{% block title %}Password Reset Email Sent{% endblock %}

{% block body %}
<p>An email has been sent that contains a link that you can click to reset your password. This link will expire in {{ tokenLifetime|date('g') }} hour(s).</p>
<p>
An email has been sent that contains a link that you can click to reset your password.
This link will expire in {{ resetToken.expirationMessageKey|trans(resetToken.expirationMessageData, 'ResetPasswordBundle') }}.
</p>
<p>If you don't receive an email please check your spam folder or <a href="{{ path('app_forgot_password_request') }}">try again</a>.</p>
{% endblock %}

0 comments on commit 6f4d27a

Please sign in to comment.