Skip to content

Commit

Permalink
Added option to resend the two factor code
Browse files Browse the repository at this point in the history
  • Loading branch information
erkens committed Aug 12, 2020
1 parent b05ac7b commit ad8d16e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Generator/CodeGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ interface CodeGeneratorInterface
* Generate a new authentication code an send it to the user.
*/
public function generateAndSend(TwoFactorTextInterface $user): void;

/**
* Resend the authentication code to the user
*/
public function reSend(TwoFactorTextInterface $user): void;
}
11 changes: 9 additions & 2 deletions Provider/TextTwoFactorProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public function beginAuthentication(AuthenticationContextInterface $context): bo

public function prepareAuthentication($user): void
{
if ($user instanceof \Erkens\Security\TwoFactorTextBundle\Model\TwoFactorTextInterface) {
if ($user instanceof TwoFactorTextInterface) {
$this->codeGenerator->generateAndSend($user);
}
}

public function validateAuthenticationCode($user, string $authenticationCode): bool
{
if (!($user instanceof \Erkens\Security\TwoFactorTextBundle\Model\TwoFactorTextInterface)) {
if (!($user instanceof TwoFactorTextInterface)) {
return false;
}

Expand All @@ -59,4 +59,11 @@ public function getFormRenderer(): TwoFactorFormRendererInterface
{
return $this->formRenderer;
}

public function resendAuthenticationCode($user): void
{
if ($user instanceof TwoFactorTextInterface) {
$this->codeGenerator->reSend($user);
}
}
}

0 comments on commit ad8d16e

Please sign in to comment.