function ip_login_user in IP Login 6.2
Implementation of hook_user().
Allows user admin of IP addresses.
Also allows users to log out without immediately logging them back in. NOTE: this module may stop other modules hook_user(logout) code firing as it destroys the session
1 string reference to 'ip_login_user'
- ip_login_update_6200 in ./
ip_login.install - Drupal 6.x-1x to 2x (Profile field -> IP Login User table) update.
File
- ./
ip_login.module, line 255 - Allow user login by IP addresses, ranges or wildcards.
Code
function ip_login_user($op, &$edit, &$account, $category = NULL) {
// if logging out and we're currently logged in by IP...
switch ($op) {
case 'logout':
// check if user can login as another, or just re-login
ip_login_user_logout();
break;
case 'form':
// add IP Login field to the User Account form.
case 'register':
// and admin add user page
if ($op == 'form' && $category == 'account' || $op == 'register') {
if (user_access('administer ip login', $user)) {
// wrap in a fieldset
$form['ip_login_matches'] = array(
'#type' => 'fieldset',
'#title' => t('IP Login'),
'#description' => ip_login_help_ranges(t('This user can be automatically logged in by IP address.')),
'#weight' => '-1',
);
$form['ip_login_matches']['ip_login_match'] = array(
'#type' => 'textfield',
'#title' => t('IP address matches'),
'#description' => t('IP matches based in format listed above. Leave blank to disable automatic login by IP for this user.'),
'#default_value' => _ip_login_get_user_range($account->uid),
'#maxlength' => 255,
);
return $form;
}
}
break;
case 'validate':
if ($op == 'form' && $category == 'account' || $op == 'register' && isset($edit['ip_login_match'])) {
//TODO: replace with regexp ideally
// validate: replace all non-numeric but legal IP range chars with '|'
$value = $edit['ip_login_match'];
$ip_login_addresses = strtr($value, ' ,.-*', '|||||');
foreach (explode('|', $ip_login_addresses) as $quad) {
if (!empty($quad) && !is_numeric($quad)) {
// bad entry, warn & bail
form_set_error('ip_login_match', t('Only numbers, spaces, commas, dots, asterisks and hyphens are allowed in IP ranges.'));
break;
}
}
}
break;
case 'update':
case 'insert':
if ($category == 'account' && isset($edit['ip_login_match'])) {
_ip_login_set_user_range($account->uid, trim(check_plain($edit['ip_login_match'])));
}
break;
case 'delete':
_ip_login_set_user_range($account->uid, NULL);
}
}