You are here

function persistent_login_user in Persistent Login 5

Same name and namespace in other branches
  1. 6 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 158

Code

function persistent_login_user($op, &$edit, &$account, $category = NULL) {
  global $user, $cookie_domain;
  switch ($op) {
    case 'login':
      if ($edit['persistent_login'] == 1) {

        /* set a new cookie, preserving series and expiration if present */
        _persistent_login_setcookie($user, $edit);
      }
      unset($_SESSION['persistent_login_login']);

      // see comment in _form_alter()
      unset($_SESSION['persistent_login_reauth']);
      break;
    case 'logout':
      if (!empty($_COOKIE[PERSISTENT_LOGIN_COOKIE])) {
        setcookie(PERSISTENT_LOGIN_COOKIE, '', time() - 86400, '/', $cookie_domain);
        unset($_SESSION['persistent_login_check']);
        unset($_SESSION['persistent_login_login']);
        unset($_SESSION['persistent_login_reauth']);
        list($uid, $series, $token) = explode(':', $_COOKIE[PERSISTENT_LOGIN_COOKIE]);
        _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()));
        $items[] = array(
          '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()),
          )),
          'class' => 'logins',
        );
        return $n > 0 ? array(
          t('Security') => $items,
        ) : NULL;
      }
      break;
    case 'update':

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