You are here

function login_security_set_login_timestamp in Login Security 6

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

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.

Also we save the login attempt event here.

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

File

./login_security.module, line 111
Login Security

Code

function login_security_set_login_timestamp($form, &$form_state) {
  $account = user_load(array(
    'name' => $form_state['values']['name'],
    'pass' => trim($form_state['values']['pass']),
    'status' => 1,
  ));
  if (variable_get('login_security_last_login_timestamp', 0) && $account->login > 0) {
    drupal_set_message(t('Your last login was !stamp', array(
      '!stamp' => format_date($account->login, 'large'),
    )), 'status');
  }
  if (variable_get('login_security_last_access_timestamp', 0) && $account->access > 0) {
    drupal_set_message(t('Your last page access (site activity) was !stamp', array(
      '!stamp' => format_date($account->access, 'large'),
    )), 'status');
  }

  // Save entry in security log, Username and IP Address
  _login_security_add_event($form_state['values']['name'], ip_address());
}