function ip_login_boot in IP Login 7.2
Same name and namespace in other branches
- 6.2 ip_login.module \ip_login_boot()
- 7.3 ip_login.module \ip_login_boot()
Implementation of hook_boot().
see http://drupal.org/node/509028
File
- ./
ip_login.module, line 30 - Allow user login by IP addresses, ranges or wildcards.
Code
function ip_login_boot() {
// skip rest of this if user is logged in
global $user;
if ($user->uid != 0) {
return;
}
// skip rest of this if the admin has disabled IP login
if (!variable_get('ip_login_enabled', 1)) {
return;
}
// Avoid settings cookies if not on an IP Login-enabled page to improve
// external caching support - http://drupal.org/node/1263234 thanks Vacilando
if (ip_login_check_path() === FALSE) {
return;
}
// check the user IP
$matched_uid = ip_login_check(ip_address());
if ($matched_uid > 0) {
$can_login_as_another_user = isset($_COOKIE[LOGIN_AS_DIFFERENT_USER]) ? $_COOKIE[LOGIN_AS_DIFFERENT_USER] : NULL;
// for clarity about every scenario, use extensive logic
if (is_null($can_login_as_another_user)) {
// first time login for user, so log in automatically.
ip_login_login($matched_uid);
drupal_goto(ltrim(request_uri(), '/'));
}
elseif ($can_login_as_another_user == FALSE) {
// user logged out, but is not allowed to use another user, so log in again.
ip_login_login($matched_uid);
drupal_goto(ltrim(request_uri(), '/'));
}
elseif ($can_login_as_another_user == TRUE) {
// user logged out, and is allowed to login as another user,
// so do nothing, just stay on this page and wait for user action.
}
else {
// do automatic login.
ip_login_login($matched_uid);
drupal_goto(ltrim(request_uri(), '/'));
}
}
}