Skip to content

Commit

Permalink
fix invalid expiresAt values for ResetPassword & VerifyEmail templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jrushlow authored and weaverryan committed Dec 18, 2020
1 parent 08727b3 commit 687cd5b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/Maker/MakeRegistrationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Validator\Validation;
use SymfonyCasts\Bundle\VerifyEmail\Model\VerifyEmailSignatureComponents;
use SymfonyCasts\Bundle\VerifyEmail\SymfonyCastsVerifyEmailBundle;

/**
Expand Down Expand Up @@ -368,7 +369,15 @@ private function getMissingComponentsComposerMessage(): ?string
$missing = false;
$composerMessage = 'composer require';

if (!class_exists(SymfonyCastsVerifyEmailBundle::class)) {
// verify-email-bundle 1.1.1 includes support for translations and a fix for the bad expiration time bug.
// we need to check that if the bundle is installed, it is version 1.1.1 or greater
if (class_exists(SymfonyCastsVerifyEmailBundle::class)) {
$reflectedComponents = new \ReflectionClass(VerifyEmailSignatureComponents::class);

if (!$reflectedComponents->hasMethod('getExpirationMessageKey')) {
throw new RuntimeCommandException('Please upgrade symfonycasts/verify-email-bundle to version 1.1.1 or greater.');
}
} else {
$missing = true;
$composerMessage = sprintf('%s symfonycasts/verify-email-bundle', $composerMessage);
}
Expand Down
11 changes: 11 additions & 0 deletions src/Maker/MakeResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Symfony\Component\Yaml\Yaml;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestTrait;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordToken;
use SymfonyCasts\Bundle\ResetPassword\Persistence\Repository\ResetPasswordRequestRepositoryTrait;
use SymfonyCasts\Bundle\ResetPassword\Persistence\ResetPasswordRequestRepositoryInterface;
use SymfonyCasts\Bundle\ResetPassword\SymfonyCastsResetPasswordBundle;
Expand Down Expand Up @@ -82,6 +83,16 @@ public function configureDependencies(DependencyBuilder $dependencies)
ORMDependencyBuilder::buildDependencies($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
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.');
}
}
}

public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/registration/twig_email.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>
Please confirm your email address by clicking the following link: <br><br>
<a href="{{ signedUrl|raw }}">Confirm my Email</a>.
This link will expire in {{ expiresAt|date('g') }} hour(s).
This link will expire in {{ expiresAtMessageKey|trans(expiresAtMessageData, 'VerifyEmailBundle') }}.
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ private function processSendingPasswordResetEmail(string $emailFormData, MailerI
->htmlTemplate('reset_password/email.html.twig')
->context([
'resetToken' => $resetToken,
'tokenLifetime' => $this->resetPasswordHelper->getTokenLifetime(),
])
;

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/resetPassword/twig_email.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

<a href="{{ url('app_reset_password', {token: resetToken.token}) }}">{{ url('app_reset_password', {token: resetToken.token}) }}</a>

<p>This link will expire in {{ tokenLifetime|date('g') }} hour(s).</p>
<p>This link will expire in {{ resetToken.expirationMessageKey|trans(resetToken.expirationMessageData, 'ResetPasswordBundle') }}.</p>

<p>Cheers!</p>
3 changes: 2 additions & 1 deletion src/Resources/skeleton/verifyEmail/EmailVerifier.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function sendEmailConfirmation(string $verifyEmailRouteName, UserInterfac

$context = $email->getContext();
$context['signedUrl'] = $signatureComponents->getSignedUrl();
$context['expiresAt'] = $signatureComponents->getExpiresAt();
$context['expiresAtMessageKey'] = $signatureComponents->getExpirationMessageKey();
$context['expiresAtMessageData'] = $signatureComponents->getExpirationMessageData();

$email->context($context);

Expand Down

0 comments on commit 687cd5b

Please sign in to comment.