Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resending the auth code #145

Closed
WebDevM4DC opened this issue May 31, 2022 · 2 comments
Closed

Resending the auth code #145

WebDevM4DC opened this issue May 31, 2022 · 2 comments

Comments

@WebDevM4DC
Copy link

WebDevM4DC commented May 31, 2022

This is not a bug report but rather a question. I would like to offer a link/button for the user to re-sent the code if he didn't received it.

Upon checking https://symfony.com/bundles/SchebTwoFactorBundle/6.x/providers/email.html#re-send-authentication-code I cannot understand how you can re-send the code from a custom route since it requires the $user interface.

Would you please offer a bit of example how to use this? Ideally I would like to add to the LoginController (which has just 2 routes, /login and /logout) another route say... /2fa-resend and that would be it.

At the moment I have created src\Interface\LoginAuthCodeInterface where I send out a custom HTML email with the code (Mailer is a service).

<?php

namespace App\Interface;

use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface;
use App\Service\Mailer;

class LoginAuthCodeInterface implements AuthCodeMailerInterface
{
    private $mailer;

    public function __construct(Mailer $mailer)
    {
        $this->mailer = $mailer;
    }

    public function sendAuthCode(TwoFactorInterface $user): void
    {
        $authCode = $user->getEmailAuthCode();

        $this->mailer->send2Fa($authCode);
    }
}

Not sure if this helps with anything, just mentioning it.

Many thanks!

@scheb
Copy link
Owner

scheb commented May 31, 2022

You can get the user object in your controller add described here: https://symfony.com/doc/current/security.html#fetching-the-user-object

In your controller, either inject or fetch scheb_two_factor.security.email.code_generator service and call the resend method with the user object.

@stale
Copy link

stale bot commented Jun 21, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale label Jun 21, 2022
@stale stale bot closed this as completed Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants