You are here

function _login_security_remove_events in Login Security 2.x

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

Remove tracked events or expire old ones.

Parameters

string $name: If specified, events for this user name will be removed.

string $host: If specified, IP Address of the name-ip pair to be removed.

4 calls to _login_security_remove_events()
login_security_cron in ./login_security.module
Implements hook_cron().
login_security_user_login in ./login_security.module
Implements hook_user_login().
login_security_user_update in ./login_security.module
Implements hook_ENTITY_TYPE_update().
login_security_validate in ./login_security.module
Implements hook_validate().

File

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

Code

function _login_security_remove_events($name = NULL, $host = NULL) {
  $conf = \Drupal::config('login_security.settings');

  // Remove selected events.
  if (!empty($name)) {
    if (!empty($host)) {
      \Drupal::database()
        ->delete('login_security_track')
        ->condition('name', $name)
        ->condition('host', $host)
        ->execute();
    }
    else {
      \Drupal::database()
        ->delete('login_security_track')
        ->condition('name', $name)
        ->execute();
    }
  }
  else {
    $request_time = \Drupal::time()
      ->getRequestTime();

    // Calculate protection time window and remove expired events.
    $time = $request_time - $conf
      ->get('track_time') * 3600;
    _login_security_remove_all_events($time);
  }
}