Permalink
Browse files

MDL-19608 - adding bulk user action to force password change, credit …

…to Iñaki Arenaza for the patch
  • Loading branch information...
1 parent e9af57f commit f7452149f821db7f9743905ca458a5531ef0f845 @arborrow arborrow committed Nov 16, 2009
@@ -24,6 +24,7 @@
case 3: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_delete.php');
case 4: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_display.php');
case 5: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_download.php');
+ case 6: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_forcepasswordchange.php');
}
}
@@ -0,0 +1,54 @@
+<?php //$Id$
+/**
+* script for bulk user force password change
+*/
+
+require_once('../../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+
+$confirm = optional_param('confirm', 0, PARAM_BOOL);
+
+require_login();
+admin_externalpage_setup('userbulk');
+require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM));
+
+$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
+
+if (empty($SESSION->bulk_users)) {
+ redirect($return);
+}
+
+admin_externalpage_print_header();
+
+//TODO: add support for large number of users
+
+if ($confirm and confirm_sesskey()) {
+ $primaryadmin = get_admin();
+
+ $in = implode(',', $SESSION->bulk_users);
+ if ($rs = get_recordset_select('user', "id IN ($in)")) {
+ while ($user = rs_fetch_next_record($rs)) {
+ if ($primaryadmin->id != $user->id and $USER->id != $user->id
+ and set_user_preference('auth_forcepasswordchange', 1, $user->id)) {
+ unset($SESSION->bulk_users[$user->id]);
+ } else {
+ notify(get_string('forcepasswordchangenot', '', fullname($user, true)));
+ }
+ }
+ rs_close($rs);
+ }
+ redirect($return, get_string('changessaved'));
+
+} else {
+ $in = implode(',', $SESSION->bulk_users);
+ $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname');
+ $usernames = implode(', ', $userlist);
+ $optionsyes = array();
+ $optionsyes['confirm'] = 1;
+ $optionsyes['sesskey'] = sesskey();
+ print_heading(get_string('confirmation', 'admin'));
+ notice_yesno(get_string('forcepasswordchangecheckfull', '', $usernames), 'user_bulk_forcepasswordchange.php', 'user_bulk.php', $optionsyes, NULL, 'post', 'get');
+}
+
+admin_externalpage_print_footer();
+?>
@@ -24,6 +24,9 @@ function definition() {
if (has_capability('moodle/user:update', $syscontext)) {
$actions[5] = get_string('download', 'admin');
}
+ if (has_capability('moodle/user:update', $syscontext)) {
+ $actions[6] = get_string('forcepasswordchange');
+ }
$objs = array();
$objs[] =& $mform->createElement('select', 'action', null, $actions);
@@ -668,7 +668,9 @@
$string['forcelanguage'] = 'Force language';
$string['forceno'] = 'Do not force';
$string['forcepasswordchange'] = 'Force password change';
+$string['forcepasswordchangecheckfull'] = 'Are you absolutely sure you want to force a password change to $a ?';
$string['forcepasswordchangehelp'] = 'Prompt user to change it on their next login';
+$string['forcepasswordchangenot'] = 'Could not force a password change to $a';
$string['forcepasswordchangenotice'] = 'You must change your password to proceed.';
$string['forcetheme'] = 'Force theme';
$string['forgotaccount'] = 'Lost password?';

0 comments on commit f745214

Please sign in to comment.