You are here

public function TfaTrustedBrowserSetup::submitSetupForm in Two-factor Authentication (TFA) 8

Submit the setup form.

Parameters

array $form: The configuration form array.

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

Return value

bool TRUE if no errors occur when saving the data.

Overrides TfaSetupInterface::submitSetupForm

File

src/Plugin/TfaSetup/TfaTrustedBrowserSetup.php, line 128

Class

TfaTrustedBrowserSetup
TFA Trusted Browser Setup Plugin.

Namespace

Drupal\tfa\Plugin\TfaSetup

Code

public function submitSetupForm(array $form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  if (isset($values['existing'])) {
    $count = 0;
    foreach ($values['existing'] as $element => $value) {
      $id = str_replace('trusted_browser_', '', $element);
      if (!$value) {
        $this
          ->deleteTrusted($id);
        $count++;
      }
    }
    if ($count) {
      \Drupal::logger('tfa')
        ->notice('Removed @num TFA trusted browsers during trusted browser setup', [
        '@num' => $count,
      ]);
    }
  }
  if (!empty($values['trust']) && $values['trust']) {
    $name = '';
    if (!empty($values['name'])) {
      $name = $values['name'];
    }
    elseif (isset($_SERVER['HTTP_USER_AGENT'])) {
      $name = $this
        ->getAgent();
    }
    $this
      ->setTrusted($this
      ->generateBrowserId(), $name);
  }
  return TRUE;
}