You are here

function _login_security_get_variables_by_name in Login Security 2.x

Same name and namespace in other branches
  1. 8 login_security.module \_login_security_get_variables_by_name()
  2. 5 login_security.module \_login_security_get_variables_by_name()
  3. 6 login_security.module \_login_security_get_variables_by_name()
  4. 7 login_security.module \_login_security_get_variables_by_name()

Helper function to get the variable array for the messages.

2 calls to _login_security_get_variables_by_name()
login_security_soft_block_validate in ./login_security.module
Temporarily deny validation to users with excess invalid login attempts.
login_security_validate in ./login_security.module
Implements hook_validate().

File

./login_security.module, line 401
Login Security module hooks.

Code

function _login_security_get_variables_by_name($name) {
  global $base_url;
  $config = \Drupal::config('login_security.settings');
  $account = user_load_by_name($name);

  // https://drupal.org/node/1744704
  if (empty($account)) {
    $account = User::load(0);
  }
  $ipaddress = \Drupal::request()
    ->getClientIp();
  $request_time = \Drupal::time()
    ->getRequestTime();
  $variables = [
    '@date' => \Drupal::service('date.formatter')
      ->format($request_time),
    '@ip' => $ipaddress,
    '@username' => $account
      ->getAccountName(),
    '@email' => $account
      ->getEmail(),
    '@uid' => $account->uid->value,
    '@site' => \Drupal::config('system.site')
      ->get('name'),
    '@uri' => $base_url,
    '@edit_uri' => Url::fromRoute('entity.user.edit_form', [
      'user' => $account->uid->value,
    ], [
      'absolute' => TRUE,
    ])
      ->toString(),
    '@hard_block_attempts' => $config
      ->get('host_wrong_count_hard'),
    '@soft_block_attempts' => $config
      ->get('host_wrong_count'),
    '@user_block_attempts' => $config
      ->get('user_wrong_count'),
    '@user_ip_current_count' => \Drupal::database()
      ->select('login_security_track', 'lst')
      ->fields('lst', [
      'id',
    ])
      ->condition('name', $name)
      ->condition('host', $ipaddress)
      ->countQuery()
      ->execute()
      ->fetchField(),
    '@ip_current_count' => \Drupal::database()
      ->select('login_security_track', 'lst')
      ->fields('lst', [
      'id',
    ])
      ->condition('host', $ipaddress)
      ->countQuery()
      ->execute()
      ->fetchField(),
    '@user_current_count' => \Drupal::database()
      ->select('login_security_track', 'lst')
      ->fields('lst', [
      'id',
    ])
      ->condition('name', $name)
      ->countQuery()
      ->execute()
      ->fetchField(),
    '@tracking_time' => $config
      ->get('track_time'),
    '@tracking_current_count' => \Drupal::database()
      ->select('login_security_track', 'lst')
      ->fields('lst', [
      'id',
    ])
      ->countQuery()
      ->execute()
      ->fetchField(),
    '@activity_threshold' => $config
      ->get('activity_threshold'),
  ];
  return $variables;
}