mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-8096 - advanced edit now mostly works, though still some parts missing; RIP changeme user :-)
This commit is contained in:
parent
82e3457600
commit
e8e0bb2d7b
@ -203,7 +203,7 @@
|
||||
$contextusers = array();
|
||||
}
|
||||
|
||||
$select = "username <> 'guest' AND username <> 'changeme' AND deleted = 0 AND confirmed = 1";
|
||||
$select = "username <> 'guest' AND deleted = 0 AND confirmed = 1";
|
||||
|
||||
$usercount = count_records_select('user', $select) - count($contextusers);
|
||||
|
||||
|
@ -227,12 +227,6 @@ if ($um->preprocess_files() && confirm_sesskey()) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->username === 'changeme') {
|
||||
notify(get_string('invaliduserchangeme', 'admin'));
|
||||
$userserrors++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// before insert/update, check whether we should be updating
|
||||
// an old record instead
|
||||
if ($allowrenames && !empty($user->oldusername) ) {
|
||||
|
@ -301,7 +301,7 @@
|
||||
$table->align = array ("left", "left", "left", "left", "left", "center", "center", "center");
|
||||
$table->width = "95%";
|
||||
foreach ($users as $user) {
|
||||
if ($user->username == 'changeme' or $user->username == 'guest') {
|
||||
if ($user->username == 'guest') {
|
||||
continue; // do not dispaly dummy new user and guest here
|
||||
}
|
||||
|
||||
|
@ -1433,6 +1433,7 @@ $string['userlist'] = 'User list';
|
||||
$string['username'] = 'Username';
|
||||
$string['usernameemailmatch'] = 'The username and email address do not relate to the same user';
|
||||
$string['usernameexists'] = 'This username already exists, choose another';
|
||||
$string['usernamelowercase'] = 'Only lowercase letters allowed';
|
||||
$string['usernamenotfound'] = 'The username was not found in the database';
|
||||
$string['usernotconfirmed'] = 'Could not confirm $a';
|
||||
$string['userpic'] = 'User picture';
|
||||
|
@ -225,7 +225,7 @@ function get_users($get=true, $search='', $confirmed=false, $exceptions='', $sor
|
||||
$LIKE = sql_ilike();
|
||||
$fullname = sql_fullname();
|
||||
|
||||
$select = 'username <> \'guest\' AND username <> \'changeme\' AND deleted = 0';
|
||||
$select = 'username <> \'guest\' AND deleted = 0';
|
||||
|
||||
if (!empty($search)){
|
||||
$search = trim($search);
|
||||
@ -280,7 +280,7 @@ function get_users_listing($sort='lastaccess', $dir='ASC', $page=0, $recordsperp
|
||||
$LIKE = sql_ilike();
|
||||
$fullname = sql_fullname();
|
||||
|
||||
$select = "deleted <> '1' AND username <> 'changeme'";
|
||||
$select = "deleted <> '1'";
|
||||
|
||||
if (!empty($search)) {
|
||||
$search = trim($search);
|
||||
@ -321,8 +321,7 @@ function get_users_confirmed() {
|
||||
FROM {$CFG->prefix}user
|
||||
WHERE confirmed = 1
|
||||
AND deleted = 0
|
||||
AND username <> 'guest'
|
||||
AND username <> 'changeme'");
|
||||
AND username <> 'guest'");
|
||||
}
|
||||
|
||||
|
||||
|
@ -589,6 +589,10 @@ function xmldb_main_upgrade($oldversion=0) {
|
||||
$result = $result && rename_field($table, $field, 'accessctrl');
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2007012500) {
|
||||
execute_sql("DELETE FROM {$CFG->prefix}user WHERE username='changeme'; ", true);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
@ -79,14 +79,7 @@
|
||||
|
||||
|
||||
$userform = new user_edit_form(null, compact('user','course','authplugin'));
|
||||
if ($user->username == 'changeme') {
|
||||
$changeme = new object();
|
||||
$changeme->id = $user->id;
|
||||
$changeme->auth = $user->auth;
|
||||
$userform->set_data($changeme);
|
||||
} else {
|
||||
$userform->set_data($user);
|
||||
}
|
||||
$userform->set_data($user);
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
if ($usernew = $userform->get_data()) {
|
||||
|
@ -50,37 +50,81 @@ class user_editadvanced_form extends moodleform {
|
||||
global $USER, $CFG;
|
||||
|
||||
$mform =& $this->_form;
|
||||
$user = get_record('user', 'id', $mform->getElementValue('id'));
|
||||
$userid = $mform->getElementValue('id');
|
||||
$user = get_record('user', 'id', $userid);
|
||||
|
||||
if ($user) {
|
||||
|
||||
// user can not change own auth method
|
||||
if ($user->id == $USER->id) {
|
||||
$mform->hardFreeze('auth');
|
||||
$mform->hardFreeze('preference_auth_forcepasswordchange');
|
||||
}
|
||||
// user can not change own auth method
|
||||
if ($userid == $USER->id) {
|
||||
$mform->hardFreeze('auth');
|
||||
$mform->hardFreeze('preference_auth_forcepasswordchange');
|
||||
}
|
||||
|
||||
// admin must choose some password and supply correct email
|
||||
if (!empty($USER->newadminuser)) {
|
||||
$mform->addRule('newpassword', get_string('required'), 'required', null, 'client');
|
||||
|
||||
$email = $mform->getElement('email');
|
||||
if ($email->getValue() == 'root@localhost') {
|
||||
$email->setValue('');
|
||||
$email_el = $mform->getElement('email');
|
||||
if ($email_el->getValue() == 'root@localhost') {
|
||||
$email_el->setValue('');
|
||||
}
|
||||
}
|
||||
|
||||
// require password for new users
|
||||
if ($userid == -1) {
|
||||
$mform->addRule('newpassword', get_string('required'), 'required', null, 'client');
|
||||
}
|
||||
|
||||
// print picture
|
||||
if (!empty($CFG->gdversion)) {
|
||||
$image = $mform->getElement('currentpicture');
|
||||
if ($user) {
|
||||
$image->setValue(print_user_picture($user->id, SITEID, $user->picture, 64, true, false, '', true));
|
||||
$image_el = $mform->getElement('currentpicture');
|
||||
if ($user and $user->picture) {
|
||||
$image_el->setValue(print_user_picture($user->id, SITEID, $user->picture, 64, true, false, '', true));
|
||||
} else {
|
||||
$image->setValue(print_user_picture(0, SITEID, 0, 64, true, false, '', true));
|
||||
$image_el->setValue(get_string('none'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function validation ($usernew) {
|
||||
global $CFG;
|
||||
|
||||
$usernew = (object)$usernew;
|
||||
$user = get_record('user', 'id', $usernew->id);
|
||||
$err = array();
|
||||
|
||||
if (!$user or $user->username !== $usernew->username) {
|
||||
//check new username does not exist
|
||||
if (record_exists('user', 'username', $usernew->username, 'mnethostid', $CFG->mnet_localhost_id)) {
|
||||
$err['username'] = get_string('usernameexists');
|
||||
}
|
||||
//check allowed characters
|
||||
if ($usernew->username !== moodle_strtolower($usernew->username)) {
|
||||
$err['username'] = get_string('usernamelowercase');
|
||||
} else {
|
||||
if (empty($CFG->extendedusernamechars)) {
|
||||
$string = eregi_replace("[^(-\.[:alnum:])]", '', $usernew->username);
|
||||
if ($usernew->username !== $string) {
|
||||
$err['username'] = get_string('alphanumerical');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$user or $user->email !== $usernew->email) {
|
||||
if (!validate_email($usernew->email)) {
|
||||
$err['email'] = get_string('invalidemail');
|
||||
} else if (record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
|
||||
$err['email'] = get_string('emailexists');
|
||||
}
|
||||
}
|
||||
|
||||
if (count($err) == 0){
|
||||
return true;
|
||||
} else {
|
||||
return $err;
|
||||
}
|
||||
}
|
||||
|
||||
function get_um() {
|
||||
return $this->_upload_manager;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2007012400; // YYYYMMDD = date
|
||||
$version = 2007012500; // YYYYMMDD = date
|
||||
// XY = increments within a single day
|
||||
|
||||
$release = '1.8 dev'; // Human-friendly version name
|
||||
|
Loading…
x
Reference in New Issue
Block a user