You are here

public function UserOneSettingsForm::buildForm in User One 8

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/UserOneSettingsForm.php, line 33

Class

UserOneSettingsForm
User One configuration form.

Namespace

Drupal\userone\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('userone.settings');
  $ban_url = Url::fromRoute('ban.admin_page')
    ->toString();
  $form['edit_access_info'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Access to user one edit blocked'),
    '#markup' => $this
      ->t('No account except user one account can edit user one account.'),
  ];
  $form['view_access_info'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Access to user one profile blocked'),
    '#markup' => $this
      ->t('No account except user one account can view user one account.'),
  ];
  $form['failed_login'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Allowed failed login attempts'),
    '#description' => $this
      ->t("This setting exposes Drupal's built-in configuration values otherwise inaccessible. It applies to all users, not just user one."),
    '#open' => TRUE,
  ];
  $form['failed_login']['user_failed_login_ip_limit'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Allowed failed login attempts for an IP address (default 50)'),
    '#options' => $this
      ->getFailedLoginAttemptsOptions(),
    '#default_value' => $config
      ->get('user_failed_login_ip_limit'),
    '#description' => $this
      ->t("Do not allow any login from the current user's IP if the limit has been reached. Default is 50 failed attempts allowed in one hour. This is independent of the per-user limit to catch attempts from one IP to log in to many different user accounts.  We have a reasonably high limit since there may be only one apparent IP for all users at an institution."),
  ];
  $form['failed_login']['user_failed_login_ip_window'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Failed login window for an IP address (default 1 hour)'),
    '#options' => $this
      ->getFailedLoginWindowOptions(),
    '#default_value' => $config
      ->get('user_failed_login_ip_window'),
    '#description' => $this
      ->t('Time period during which failed logins are accounted for.'),
  ];
  $form['failed_login']['block_ip_on_failed_login_ip'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Permanently block IP when failed logins breaks threshold. (<a href="@url">See blocked IPs</a>)', [
      '@url' => $ban_url,
    ]),
    '#default_value' => $config
      ->get('block_ip_on_failed_login_ip'),
    '#description' => $this
      ->t('User one account will be notified when an IP is blocked.'),
  ];
  $form['failed_login']['divider'] = [
    '#type' => 'item',
    '#markup' => '<hr/>',
  ];
  $form['failed_login']['user_failed_login_user_limit'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Allowed failed login attempts for an account (default 5)'),
    '#options' => $this
      ->getFailedLoginAttemptsOptions(),
    '#default_value' => $config
      ->get('user_failed_login_user_limit'),
    '#description' => $this
      ->t('User will be allowed to attempt logins this many times within the period (see below).'),
  ];
  $form['failed_login']['user_failed_login_user_window'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Failed login window for an account (default 6 hours)'),
    '#options' => $this
      ->getFailedLoginWindowOptions(),
    '#default_value' => $config
      ->get('user_failed_login_user_window'),
    '#description' => $this
      ->t('Number of failed logins for an account will be accounted for this period'),
  ];
  $form['failed_login']['block_ip_on_failed_login_user1'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Permanently block IP when failed logins <strong>for user one</strong> breaks threshold. (<a href="@url">See blocked IPs</a>)', [
      '@url' => $ban_url,
    ]),
    '#default_value' => $config
      ->get('block_ip_on_failed_login_user1'),
    '#description' => $this
      ->t('User one account will be notified when an IP is blocked.'),
  ];
  return parent::buildForm($form, $form_state);
}