You are here

function persistent_login_user in Persistent Login 6

Same name and namespace in other branches
  1. 5 persistent_login.module \persistent_login_user()

Implementation of hook_user().

1 call to persistent_login_user()
_persistent_login_check in ./persistent_login.module
_persistent_login_check(). Do the real work. Note that we may be in BOOTSTRAP_PAGE_CACHE mode with few modules loaded.

File

./persistent_login.module, line 190
Provide a "Remember Me" checkbox in the login form.

Code

function persistent_login_user($op, &$edit, &$account, $category = NULL) {
  global $user;
  switch ($op) {
    case 'login':

      // If we are coming from a login form, $edit['persistent_login']
      // is set if the user checked it.  If we are coming from
      // persistent_login_check(), $edit['persistent_login'] is also
      // set along with pl_series and pl_expiration.  Either way, issue a
      // new PL cookie, preserving series and expiration if present.
      if (!empty($edit['persistent_login'])) {
        _persistent_login_create_cookie($account, $edit);
      }

      // Assume this is a non-PL login; clear persistent_login_login.
      // If this is a PL login, it will be set again by
      // _persistent_login_check (our caller).
      unset($_SESSION['persistent_login_login']);

      // see comment in _form_alter()
      unset($_SESSION['persistent_login_reauth']);
      break;
    case 'logout':
      $cookie_name = _persistent_login_get_cookie_name();
      if (!empty($_COOKIE[$cookie_name])) {
        _persistent_login_setcookie($cookie_name, '', time() - 86400);
        unset($_SESSION['persistent_login_check']);
        unset($_SESSION['persistent_login_login']);
        unset($_SESSION['persistent_login_reauth']);
        list($uid, $series, $token) = explode(':', $_COOKIE[$cookie_name]);
        _persistent_login_invalidate('logout', "uid = %d AND series = '%s'", $uid, $series);
      }
      break;
    case 'view':
      if ($user->uid == $account->uid || user_access('administer Persistent Login')) {
        $n = db_result(db_query('SELECT COUNT(*) FROM {persistent_login} WHERE uid = %d AND (expires = 0 OR expires > %d)', $account->uid, time()));
        if ($n > 0) {
          if (!isset($account->content['security'])) {
            $account->content['security'] = array();
          }
          $account->content['security'] += array(
            '#type' => 'user_profile_category',
            '#title' => t('Security'),
            '#weight' => 10,
          );
          $account->content['security']['persistent_login'] = array(
            '#type' => 'user_profile_item',
            '#title' => t('Remembered logins'),
            '#value' => t('@acct %n persistent login session(s) created with the "Remember Me" login option on this site.  If you no longer trust the computer(s) on which these remembered sessions were created or think your account has been compromised for any reason, you can !erase_link.  This will not log you out of your current session but you will have to provide your username and password to log in the next time you visit this site.', array(
              '@acct' => $user->uid == $account->uid ? t('You have') : t('User @user has', array(
                '@user' => $account->name,
              )),
              '%n' => $n,
              '!erase_link' => l(t('erase persistent logins now'), 'persistent_login/erase/' . $account->uid, array(), drupal_get_destination()),
            )),
            '#attributes' => array(
              'class' => 'logins',
            ),
          );
        }
      }
      break;
    case 'update':
      if (empty($edit['pass'])) {
        break;
      }

    // If the password is modified, fall through to wipe all persistent logins.
    case 'delete':
      _persistent_login_invalidate($op, 'uid = %d', $account->uid);
      unset($_SESSION['persistent_login_check']);
      unset($_SESSION['persistent_login_login']);
      break;
  }
}