kodal-uk / craft-email-2fa

Email based Two-factor authentication plugin for Craft CMS
MIT License
4 stars 6 forks source link

Multi Site - Redirect before verify #3

Open ricardonunesdev opened 4 years ago

ricardonunesdev commented 4 years ago

Hey,

I'm having an issue with Email-2FA in a Multi Site install of Craft.

The redirection before the verify form is going to the main site and not to the secondary site I'm trying to log into. The plugin is redirecting before the verify form shows up, so the verify URL is already on the main site. If I manually change the URL in the address bar to the /verify under the secondary site, and then validate, it works as expected.

I've narrowed it down to this function in the services/Auth.php class, which redirects to the value set in the control panel:

/**
* @throws \craft\errors\MissingComponentException
*/
public function requireLogin()
{
    if ( ! $this->isLoggedIn()) {
        $this->response->redirect($this->settings->verifyRoute);
    }
}

Is it possible to have this route relative to the site the user is visiting? If so, how can I do this? Can it be done in the control panel or do I have to change part of your code?

Thank you and best regards

ricardonunesdev commented 4 years ago

Hey,

Actually fixed it by adding the URL of the current site, like this:

public function requireLogin()
{
    if ( ! $this->isLoggedIn()) {
        $this->response->redirect(UrlHelper::siteUrl() . $this->settings->verifyRoute);
    }
}

And imported the UrlHelper class at the top:

use craft\helpers\UrlHelper;

Seems to work for all cases.

Do you want a PR for this?

Best regards

ricardonunesdev commented 4 years ago

Done ^_^

PR: https://github.com/kodal-uk/craft-email-2fa/pull/4

Best regards, and thank you for a great plugin