Skip to content

Commit

Permalink
MDL-8096 - advanced edit now mostly works, though still some parts mi…
Browse files Browse the repository at this point in the history
…ssing; RIP changeme user :-)
  • Loading branch information
skodak committed Jan 25, 2007
1 parent 82e3457 commit e8e0bb2
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 36 deletions.
2 changes: 1 addition & 1 deletion admin/roles/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 0 additions & 6 deletions admin/uploaduser.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,6 @@
}
}

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) ) {
Expand Down
2 changes: 1 addition & 1 deletion admin/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions lang/en_utf8/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,7 @@
$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';
Expand Down
7 changes: 3 additions & 4 deletions lib/datalib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'");
}


Expand Down
4 changes: 4 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand Down
9 changes: 1 addition & 8 deletions user/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
74 changes: 59 additions & 15 deletions user/editadvanced_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,79 @@ function definition_after_data() {
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_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 {
$image->setValue(print_user_picture(0, SITEID, 0, 64, true, false, '', true));
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() {
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8e0bb2

Please sign in to comment.