function password_policy_password_change_settings_submit in Password Policy 6
Same name and namespace in other branches
- 7 password_policy.admin.inc \password_policy_password_change_settings_submit()
Submit hook for forced password change form.
File
- ./
password_policy.admin.inc, line 422 - Admin page callback file for the password_policy module.
Code
function password_policy_password_change_settings_submit($form, &$form_state) {
global $user;
$selected_roles = array();
variable_set('password_policy_new_login_change', $form_state['values']['password_policy_new_login_change']);
variable_set('password_policy_exclude_pages', $form_state['values']['password_policy_exclude_pages']);
if ($form_state['values']['password_policy_new_login_change'] == 1) {
watchdog('password policy', t('New user accounts must change password on new login enabled by !admin.', array(
'!admin' => $user->name,
)), array(), WATCHDOG_NOTICE);
}
$form_state['values']['password_policy_new_login_change'] ? drupal_set_message(t('New users will be required to change their password on first-time login.')) : drupal_set_message(t('New users will not be required to change their pasword on first-time login.'));
foreach ($form_state['values']['password_policy_force_change_roles'] as $role) {
// skip over null values returned by unselected roles
if ($role == 0) {
continue;
}
$uids = array();
// special handling for authenticated users role
// since this role makes no entries in the users_roles table
if ($role == 2) {
// no point in flagging Anonymous since they can't log in anyway
$db_uids = db_query('SELECT uid FROM {users} WHERE uid <> 0');
}
else {
$db_uids = db_query('SELECT uid FROM {users_roles} WHERE rid = %d', $role);
}
while ($uid = db_result($db_uids)) {
if ($uid == 1 && variable_get('password_policy_admin', 0) || $uid > 1) {
$uids[] = $uid;
}
}
if (!empty($uids)) {
$sql = 'UPDATE {password_policy_force_change} SET force_change = 1 WHERE uid IN (' . db_placeholders($uids, 'int') . ')';
db_query($sql, $uids);
}
$selected_roles[] = $role;
}
if (count($selected_roles)) {
$roles = user_roles(TRUE);
$list = array();
foreach ($selected_roles as $sr) {
$list[] = $roles[$sr];
}
$list = implode(', ', $list);
drupal_set_message(t('Users in the following roles will be required to immediately change their password: %list', array(
'%list' => $list,
)), 'status');
watchdog('password policy', t('!admin has flagged users in the following roles to immediately change their password: %list', array(
'%list' => $list,
'!admin' => $user->name,
)), array(), WATCHDOG_NOTICE);
}
else {
drupal_set_message(t('No roles were selected.'));
}
}