function login_user_block_user_name in Login Security 7
Same name and namespace in other branches
- 8 login_security.module \login_user_block_user_name()
- 5 login_security.module \login_user_block_user_name()
- 6 login_security.module \login_user_block_user_name()
- 2.x login_security.module \login_user_block_user_name()
Block a user by user name. If no user id then block current user.
1 call to login_user_block_user_name()
- login_security_validate in ./
login_security.module - Implements hook_validate().
File
- ./
login_security.module, line 390 - Login Security
Code
function login_user_block_user_name($variables) {
// If the user exists.
if ($variables['@uid'] > 1) {
// Modifying the user table is not an option so it disables the user hooks.
// Need to do firing the hook so user_notifications can be used.
// db_query("UPDATE {users} SET status = 0 WHERE uid = %d", $uid);
$uid = $variables['@uid'];
$account = user_load($uid);
// Block account if is active.
if ($account->status == 1) {
user_save($account, array(
'status' => 0,
), NULL);
// Remove user from site now.
drupal_session_destroy_uid($uid);
// The watchdog alert is set to 'user' so it will show with other blocked
// user messages.
watchdog('user', 'Blocked user @username due to security configuration.', $variables, WATCHDOG_NOTICE, l(t('edit user'), "user/{$variables['@uid']}/edit", array(
'query' => array(
'destination' => 'admin/user/user',
),
)));
// Also notify the user that account has been blocked.
form_set_error('void', login_security_t(variable_get('login_security_user_blocked', LOGIN_SECURITY_USER_BLOCKED), $variables));
// Send admin email.
$user_blocked_email_user = variable_get('login_security_user_blocked_email_user', LOGIN_SECURITY_USER_BLOCKED_EMAIL_USER);
if ($user_blocked_email_user !== '') {
$from = variable_get('site_mail', ini_get('sendmail_from'));
$admin_mail = db_select('users', 'u')
->fields('u', array(
'mail',
))
->condition('name', $user_blocked_email_user)
->execute()
->fetchField();
return drupal_mail('login_security', 'block_user_notify', $admin_mail, language_default(), $variables, $from, TRUE);
}
}
}
}