Skip to content

Commit bd1e578

Browse files
jrushlowweaverryan
authored andcommitted
[Reset-Password] use expiration translation in check email route
1 parent 0f4d4eb commit bd1e578

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/Maker/MakeResetPassword.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Symfony\Component\Console\Input\InputInterface;
3434
use Symfony\Component\Mailer\MailerInterface;
3535
use Symfony\Component\Yaml\Yaml;
36+
use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait;
3637
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
3738
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestTrait;
3839
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordToken;
@@ -84,13 +85,11 @@ public function configureDependencies(DependencyBuilder $dependencies)
8485

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

87-
// reset-password-bundle 1.2.1 includes support for translations and a fix for the bad expiration time bug.
88-
// we need to check that version 1.2.1 is installed
88+
// reset-password-bundle 1.3 includes helpers to get/set a ResetPasswordToken object from the session.
89+
// we need to check that version 1.3 is installed
8990
if (class_exists(ResetPasswordToken::class)) {
90-
$reflectedToken = new \ReflectionClass(ResetPasswordToken::class);
91-
92-
if (!$reflectedToken->hasMethod('getExpirationMessageKey')) {
93-
throw new RuntimeCommandException('Please upgrade symfonycasts/reset-password-bundle to version 1.2.1 or greater.');
91+
if (!method_exists(ResetPasswordControllerTrait::class, 'getTokenObjectFromSession')) {
92+
throw new RuntimeCommandException('Please upgrade symfonycasts/reset-password-bundle to version 1.3 or greater.');
9493
}
9594
}
9695
}

src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ public function request(Request $request, MailerInterface $mailer): Response
7676
public function checkEmail(): Response
7777
{
7878
// We prevent users from directly accessing this page
79-
if (!$this->canCheckEmail()) {
79+
if (null === ($resetToken = $this->getTokenObjectFromSession())) {
8080
return $this->redirectToRoute('app_forgot_password_request');
8181
}
8282

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

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

158-
// Marks that you are allowed to see the app_check_email page.
159-
$this->setCanCheckEmailInSession();
160-
161158
// Do not reveal whether a user account was found or not.
162159
if (!$user) {
163160
return $this->redirectToRoute('app_check_email');
@@ -190,6 +187,9 @@ private function processSendingPasswordResetEmail(string $emailFormData, MailerI
190187

191188
$mailer->send($email);
192189

190+
// Store the token object in session for retrieval in check-email route.
191+
$this->setTokenObjectInSession($resetToken);
192+
193193
return $this->redirectToRoute('app_check_email');
194194
}
195195
}

src/Resources/skeleton/resetPassword/twig_check_email.tpl.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
{% block title %}Password Reset Email Sent{% endblock %}
44

55
{% block body %}
6-
<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>
6+
<p>
7+
An email has been sent that contains a link that you can click to reset your password.
8+
This link will expire in {{ resetToken.expirationMessageKey|trans(resetToken.expirationMessageData, 'ResetPasswordBundle') }}.
9+
</p>
710
<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>
811
{% endblock %}

0 commit comments

Comments
 (0)