You are here

public function BasicDisable::validateForm in Two-factor Authentication (TFA) 8

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormBase::validateForm

File

src/Form/BasicDisable.php, line 162

Class

BasicDisable
TFA disable form router.

Namespace

Drupal\tfa\Form

Code

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

  /** @var \Drupal\user\Entity\User $user */
  $user = $this->userStorage
    ->load($this
    ->currentUser()
    ->id());
  $storage = $form_state
    ->getStorage();
  $account = $storage['account'];

  // Allow administrators to disable TFA for another account.
  if ($account
    ->id() != $user
    ->id() && $user
    ->hasPermission('administer users')) {
    $account = $user;
  }

  // Check password.
  $current_pass = $this->passwordChecker
    ->check(trim($form_state
    ->getValue('current_pass')), $account
    ->getPassword());
  if (!$current_pass) {
    $form_state
      ->setErrorByName('current_pass', $this
      ->t("Incorrect password."));
  }
}