function ip_login_user_logout in IP Login 7.2
Same name and namespace in other branches
- 6.2 ip_login.module \ip_login_user_logout()
- 7.3 ip_login.module \ip_login_user_logout()
- 4.x ip_login.module \ip_login_user_logout()
Implementation of hook_user_logout
Called from hook_user on logout, most of the code taken from user_logout() and _drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION). D7-changes: this is now an implementation of a hook, so:
- Only do a logout, leave the automatic login to ip_login_boot;
- prevent logging out if needed, just by calling drupal_goto()
- N.B. check user_logout() in user.pages.inc; this is the calling function;
- N.B. check devel_switch_user() in devel.module; here users are switched, too;
File
- ./
ip_login.module, line 543 - Allow user login by IP addresses, ranges or wildcards.
Code
function ip_login_user_logout() {
// prevent recursive call via user_module_invoke() / module_invoke_all() in user.pages.inc
if (!ip_login_is_possible()) {
return;
}
else {
$_SESSION[IP_CHECKED] = FALSE;
$_SESSION[IP_UID_MATCH] = 0;
}
global $user;
// store whether this user can log back in automatically
$can_login_as_another_user = _ip_login_can_login_as_another_user($user);
// sets indicator to behaviour in hook_boot().
$expire = 0;
// Cookie expires at the end of the session (when the browser closes).
setcookie(LOGIN_AS_DIFFERENT_USER, $can_login_as_another_user, $expire, '/');
if (!$can_login_as_another_user) {
// @todo: it is possible that some other hook_user_logout() has been called already
// does this generate an undetermined state?
$message = t(variable_get('ip_login_logged_back_in', 'This account does not have permission to log out once logged in automatically. You have been logged back in.'));
$message = token_replace($message, array(
'user' => $user,
), array(
'clear' => TRUE,
));
drupal_set_message($message, 'warning');
// show the login page
drupal_goto(variable_get('ip_login_destination', 'user'));
}
}