You are here

public function TfaLoginForm::loginWithTfa in Two-factor Authentication (TFA) 8

Handle login when TFA is set up for the user.

TFA is set up for this user, and $this->tfaContext is initialized.

If any of the TFA plugins allows login, then finalize the login. Otherwise, set a redirect to enter a second factor.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The state of the login form.

1 call to TfaLoginForm::loginWithTfa()
TfaLoginForm::submitForm in src/Form/TfaLoginForm.php
Login submit handler.

File

src/Form/TfaLoginForm.php, line 187

Class

TfaLoginForm
TFA user login form.

Namespace

Drupal\tfa\Form

Code

public function loginWithTfa(FormStateInterface $form_state) {
  $user = $this->tfaContext
    ->getUser();
  if ($this->tfaContext
    ->pluginAllowsLogin()) {
    $this->tfaContext
      ->doUserLogin();
    $this
      ->messenger()
      ->addStatus($this
      ->t('You have logged in on a trusted browser.'));
    $form_state
      ->setRedirect('<front>');
  }
  else {

    // Begin TFA and set process context.
    // @todo This is used in send plugins which has not been implemented yet.
    // $this->begin($tfaValidationPlugin);
    $parameters = $this->destination
      ->getAsArray();
    $parameters['user'] = $user
      ->id();
    $parameters['hash'] = $this
      ->getLoginHash($user);
    $this
      ->getRequest()->query
      ->remove('destination');
    $form_state
      ->setRedirect('tfa.entry', $parameters);
  }
}