]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8096 - advanced edit now mostly works, though still some parts missing; RIP chang...
authorskodak <skodak>
Thu, 25 Jan 2007 11:03:33 +0000 (11:03 +0000)
committerskodak <skodak>
Thu, 25 Jan 2007 11:03:33 +0000 (11:03 +0000)
admin/roles/assign.php
admin/uploaduser.php
admin/user.php
lang/en_utf8/moodle.php
lib/datalib.php
lib/db/upgrade.php
user/edit.php
user/editadvanced_form.php
version.php

index 469ad31a472b467c02e38eefb95435b4348172e7..70b0716c4e0d0290b9e4605bf6c9d3cea23ecc3a 100755 (executable)
             $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);
 
index 34cbb77b9b8966408562c2da1914df28526e1818..d0113c9de1f0e4fde8acddda2d023a1ce87552cb 100755 (executable)
@@ -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) ) {
index 2fe06de1a3c935d9ccbc9dab9f4e8cfa9c154af2..190f90f6c0576c6e960b389a0c6a02dd7b640a3c 100644 (file)
         $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
             }
 
index e19c12d84600afe8a92fc0deca820278816fe1fb..2ea6213708dd0908e692fdebb1614c680df433cb 100644 (file)
@@ -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';
index 0f04b29ac6982707d174c209c5ec9e4c87f52f43..4f27c91984b8880083b46115c6b251791a0812a7 100644 (file)
@@ -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'");
 }
 
 
index bfc5871e8668cef47d906e464fb1d8746d003f2b..e077a6fb0251e43ca5156f67c7f947ae299632fe 100644 (file)
@@ -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;
 
 }
index 53abc59c429f33c905e5af61577b58adaf683ac9..a045809810ad382e30186b82880ce29d1abb2dbc 100644 (file)
 
 
     $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()) {
index ce1d0316192680ae148864db974b5102ac4b93a7..ad6e2c82a69e03877fec71ff4ca83383d8e484cf 100644 (file)
@@ -50,35 +50,79 @@ 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_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() {
index e2778253e93db3c9b0d3bae283e7fe126906e987..fc7529cfe41fcde546bf39ccb6686f076a908ee0 100644 (file)
@@ -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