You are here

function login_security_set_login_timestamp in Login Security 7

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

Save login attempt and save login/access timestamps.

Previous incarnations of this code put it in hook_submit or hook_user, but since Drupal core validation updates the login timestamp, we have to set the message before it gets updated with the current login instance.

1 string reference to 'login_security_set_login_timestamp'
login_security_form_alter in ./login_security.module
Implements hook_form_alter().

File

./login_security.module, line 108
Login Security

Code

function login_security_set_login_timestamp($form, &$form_state) {
  $account = db_select('users', 'u')
    ->fields('u', array(
    'login',
    'access',
  ))
    ->condition('name', $form_state['values']['name'])
    ->condition('status', 1)
    ->execute()
    ->fetchAssoc();

  // Save entry in security log, Username and IP Address.
  _login_security_add_event($form_state['values']['name'], ip_address());
  if (empty($account)) {
    return;
  }
  _login_security_login_timestamp($account['login']);
  _login_security_access_timestamp($account['access']);
}