You are here

function _login_security_get_variables_by_name in Login Security 7

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. 2.x login_security.module \_login_security_get_variables_by_name()

Helper function to get the variable array for the messages.

3 calls to _login_security_get_variables_by_name()
login_security_nagios in ./login_security.module
Implements hook_nagios().
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 429
Login Security

Code

function _login_security_get_variables_by_name($name) {
  $account = user_load_by_name($name);

  // https://drupal.org/node/1744704
  if (empty($account)) {
    $account = user_load(0);
  }
  $ipaddress = ip_address();
  global $base_url;
  $variables = array(
    '@date' => format_date(REQUEST_TIME),
    '@ip' => $ipaddress,
    '@username' => $account->name,
    '@email' => $account->mail,
    '@uid' => $account->uid,
    '@site' => variable_get('site_name', 'drupal'),
    '@uri' => $base_url,
    '@edit_uri' => url('user/' . $account->uid . '/edit', array(
      'absolute' => TRUE,
    )),
    '@hard_block_attempts' => variable_get('login_security_host_wrong_count_hard', LOGIN_SECURITY_HOST_WRONG_COUNT_HARD),
    '@soft_block_attempts' => variable_get('login_security_host_wrong_count', LOGIN_SECURITY_USER_WRONG_COUNT),
    '@user_block_attempts' => variable_get('login_security_user_wrong_count', LOGIN_SECURITY_USER_WRONG_COUNT),
    '@user_ip_current_count' => db_select('login_security_track', 'lst')
      ->fields('lst', array(
      'id',
    ))
      ->condition('name', $name)
      ->condition('host', $ipaddress)
      ->countQuery()
      ->execute()
      ->fetchField(),
    '@ip_current_count' => db_select('login_security_track', 'lst')
      ->fields('lst', array(
      'id',
    ))
      ->condition('host', $ipaddress)
      ->countQuery()
      ->execute()
      ->fetchField(),
    '@user_current_count' => db_select('login_security_track', 'lst')
      ->fields('lst', array(
      'id',
    ))
      ->condition('name', $name)
      ->countQuery()
      ->execute()
      ->fetchField(),
    '@tracking_time' => variable_get('login_security_track_time', LOGIN_SECURITY_TRACK_TIME),
    '@tracking_current_count' => db_select('login_security_track', 'lst')
      ->fields('lst', array(
      'id',
    ))
      ->countQuery()
      ->execute()
      ->fetchField(),
    '@activity_threshold' => variable_get('login_security_activity_threshold', LOGIN_SECURITY_ACTIVITY_THRESHOLD),
  );
  return $variables;
}