You are here

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

Login submit handler.

Determine if TFA process applies. If not, call the parent form submit.

Overrides UserLoginForm::submitForm

File

src/Form/TfaLoginForm.php, line 137

Class

TfaLoginForm
TFA user login form.

Namespace

Drupal\tfa\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // The user ID must not be NULL.
  if (empty($uid = $form_state
    ->get('uid'))) {
    return;
  }

  // Similar to tfa_user_login() but not required to force user logout.

  /** @var \Drupal\user\Entity\User $user */
  $user = $this->userStorage
    ->load($uid);
  $this->tfaContext = new TfaContext($this->tfaValidationManager, $this->tfaLoginManager, $this
    ->configFactory(), $user, $this->userData, $this
    ->getRequest());

  /* Uncomment when things go wrong and you get logged out.
     user_login_finalize($user);
     $form_state->setRedirect('<front>');
     return;
      */

  // Stop processing if Tfa is not enabled.
  if (!$this->tfaContext
    ->isModuleSetup() || !$this->tfaContext
    ->isTfaRequired()) {
    parent::submitForm($form, $form_state);
  }
  else {

    // Setup TFA.
    if ($this->tfaContext
      ->isReady()) {
      $this
        ->loginWithTfa($form_state);
    }
    else {
      $this
        ->loginWithoutTfa($form_state);
    }
  }
}