From bd1e578debad36b990b2562412f3ed8f4db62ea8 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 12 Jan 2021 09:52:37 -0500 Subject: [PATCH] [Reset-Password] use expiration translation in check email route --- src/Maker/MakeResetPassword.php | 11 +++++------ .../resetPassword/ResetPasswordController.tpl.php | 10 +++++----- .../skeleton/resetPassword/twig_check_email.tpl.php | 5 ++++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Maker/MakeResetPassword.php b/src/Maker/MakeResetPassword.php index f2f0311a4..7db7fd3c6 100644 --- a/src/Maker/MakeResetPassword.php +++ b/src/Maker/MakeResetPassword.php @@ -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; @@ -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.'); } } } diff --git a/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php b/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php index 3c39802ad..b662e0b1e 100644 --- a/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php +++ b/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php @@ -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, ]); } @@ -155,9 +155,6 @@ private function processSendingPasswordResetEmail(string $emailFormData, MailerI '' => $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'); @@ -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'); } } diff --git a/src/Resources/skeleton/resetPassword/twig_check_email.tpl.php b/src/Resources/skeleton/resetPassword/twig_check_email.tpl.php index 35f115341..00701d0e7 100644 --- a/src/Resources/skeleton/resetPassword/twig_check_email.tpl.php +++ b/src/Resources/skeleton/resetPassword/twig_check_email.tpl.php @@ -3,6 +3,9 @@ {% block title %}Password Reset Email Sent{% endblock %} {% block body %} -

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).

+

+ 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') }}. +

If you don't receive an email please check your spam folder or try again.

{% endblock %}