public function TfaLoginForm::loginWithoutTfa in Two-factor Authentication (TFA) 8
Handle the case where TFA is not yet set up.
TFA is not set up for this user, and $this->tfaContext is initialized.
If the user has any remaining logins, then finalize the login with a message to set up TFA. Otherwise, leave the user logged out.
Parameters
\Drupal\Core\Form\FormStateInterface $form_state: The state of the login form.
1 call to TfaLoginForm::loginWithoutTfa()
- TfaLoginForm::submitForm in src/
Form/ TfaLoginForm.php - Login submit handler.
File
- src/
Form/ TfaLoginForm.php, line 217
Class
- TfaLoginForm
- TFA user login form.
Namespace
Drupal\tfa\FormCode
public function loginWithoutTfa(FormStateInterface $form_state) {
// User may be able to skip TFA, depending on module settings and number of
// prior attempts.
$remaining = $this->tfaContext
->remainingSkips();
if ($remaining) {
$user = $this->tfaContext
->getUser();
$tfa_setup_link = Url::fromRoute('tfa.overview', [
'user' => $user
->id(),
])
->toString();
$message = $this
->formatPlural($remaining - 1, 'You are required to setup two-factor authentication <a href="@link">here.</a> You have @remaining attempt left. After this you will be unable to login.', 'You are required to setup two-factor authentication <a href="@link">here.</a> You have @remaining attempts left. After this you will be unable to login.', [
'@remaining' => $remaining - 1,
'@link' => $tfa_setup_link,
]);
$this
->messenger()
->addError($message);
$this->tfaContext
->hasSkipped();
$this->tfaContext
->doUserLogin();
$form_state
->setRedirect('<front>');
}
else {
$message = $this
->config('tfa.settings')
->get('help_text');
$this
->messenger()
->addError($message);
$this
->logger('tfa')
->notice('@name has no more remaining attempts for bypassing the second authentication factor.', [
'@name' => $this->tfaContext
->getUser()
->getAccountName(),
]);
}
}