]> git.mjollnir.org Git - moodle.git/commitdiff
mnet: user/* now handles remote users and multi-auth
authormartinlanghoff <martinlanghoff>
Thu, 4 Jan 2007 03:01:30 +0000 (03:01 +0000)
committermartinlanghoff <martinlanghoff>
Thu, 4 Jan 2007 03:01:30 +0000 (03:01 +0000)
user/edit.html
user/edit.php
user/tabs.php
user/view.php

index 86878fc2205c92afbb979d9b1167a77b1c40d649..4b9fc4ae5676dcd9ab4e9bf192e3f23b35768e3c 100644 (file)
 if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
     $theadmin = get_admin(); // returns false during install
     $adminself = (!empty($theadmin) and ($theadmin->id == $USER->id) and ($USER->id == $user->id));
+    $userauth = get_auth_plugin($user->auth);
     echo '<tr>';
     echo '<th>'.get_string('username').':</th>';
-    if ($adminself || is_internal_auth($user->auth) ){
+    if ($adminself or $userauth->is_internal()) {
         echo "<td><input type=\"text\" name=\"username\" size=\"20\" alt=\"".get_string("username")."\" value=\"";
         p($user->username);
         echo "\" />";
@@ -58,7 +59,7 @@ if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SI
         echo "</td></tr>\n";
     }
 
-    if ($adminself || is_internal_auth($user->auth) || (!empty($CFG->{'auth_'.$user->auth.'_stdchangepassword'}))) {
+    if ($adminself or $userauth->can_change_password()) {
         echo '<tr>';
         echo '<th>'.get_string('newpassword').':</th>';
         echo "<td><input type=\"text\" name=\"newpassword\" size=\"20\" alt=\"".get_string("newpassword")."\" value=\"";
@@ -73,7 +74,7 @@ if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SI
         }
         echo "</td>";
         echo "</tr>\n";
-        if (!$adminself && (!empty($CFG->{'auth_'.$user->auth.'_stdchangepassword'}) || is_internal_auth())){
+        if (!$adminself and $userauth->can_change_password()) {
              if (get_user_preferences('auth_forcepasswordchange', NULL, $user->id)) {
                  $checked = ' checked="checked" ';
              } else {
index 6671fde741ba2c874c222c70be147f115a172b91..e38fb92dcb6cf14ceac4661046ad665a781c3080 100644 (file)
         require_login($course->id);
     }
 
+    // remote users cannot be edited
+    if (is_mnet_remote_user($user)) {
+        redirect($CFG->wwwroot . "/user/view.php?id=$id&course={$course->id}");
+    }
+
     if ($USER->id <> $user->id) {    // Current user editing someone else's profile
         if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) { // Current user can update user profiles
             if ($mainadmin = get_admin()) {        
     // load the relevant auth libraries
     if (!empty($user->auth)) { 
         $auth = $user->auth;
-        if (!file_exists("$CFG->dirroot/auth/$auth/lib.php")) {
-            trigger_error("Can't find auth module $auth , default to internal.");
-            $auth = "manual";    // Can't find auth module, default to internal
+        // TODO: spit dummy if $auth doesn't exist
+        if (! exists_auth_plugin($auth)) {
+            trigger_error("Can't find auth module '$auth', default to internal.");
+            $auth = "manual";
         }
-        require_once("$CFG->dirroot/auth/$auth/lib.php");
+        $authplugin = get_auth_plugin($auth);
+    }
+    else {
+        $authplugin = get_auth_plugin($CFG->auth);
     }
 
     
         // override locked values
         if (!has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {      
             $fields = get_user_fieldnames();
-            $authconfig = get_config( 'auth/' . $user->auth );
             foreach ($fields as $field) {
                 $configvariable = 'field_lock_' . $field;
-                if ( empty($authconfig->{$configvariable}) ) {
+                if ( empty($authplugin->config->{$configvariable}) ) {
                     continue; //no locking set
                 }
-                if ( $authconfig->{$configvariable} === 'locked'
-                     || ($authconfig->{$configvariable} === 'unlockedifempty' && !empty($user->$field)) ) {
+                if ( $authplugin->config->{$configvariable} === 'locked'
+                     or ($authplugin->config->{$configvariable} === 'unlockedifempty' and !empty($user->$field))) {
                     if (!empty( $user->$field)) {
                         $usernew->$field = addslashes($user->$field);
                     }
                 if (!empty($usernew->newpassword)) {
                     $usernew->password = hash_internal_user_password($usernew->newpassword);
                     // update external passwords
-                    if (!empty($CFG->{'auth_'. $user->auth.'_stdchangepassword'})) {
-                        if (function_exists('auth_user_update_password')){
-                            if (!auth_user_update_password($user->username, $usernew->newpassword)){
+                    // TODO: this was using $user->auth possibly overriding $authplugin above. Can we guarantee $user->auth being something valid?
+                    if ($authplugin->can_change_password()) {
+                        if (method_exists($authplugin, 'user_update_password')){
+                            if (!$authplugin->user_update_password($user->username, $usernew->newpassword)){
                                 error('Failed to update password on external auth: ' . $user->auth .
                                         '. See the server logs for more details.');
                             }
 
             $userold = get_record('user','id',$usernew->id);
             if (update_record("user", $usernew)) {
-                if (function_exists("auth_user_update")){
+                if (method_exists($authplugin, "user_update")){
                     // pass a true $userold here 
-                    if (!auth_user_update($userold, $usernew)) {
+                    if (! $authplugin->user_update($userold, $usernew)) {
                         // auth update failed, rollback for moodle
                         update_record("user", $userold);
                         error('Failed to update user data on external auth: '.$user->auth.
         echo '<script type="text/javascript">'."\n";
         echo '<!--'."\n";
 
-        $authconfig = get_config( 'auth/' . $user->auth );
-        
         foreach ($fields as $field) {
             $configvariable = 'field_lock_' . $field;
-            if (isset($authconfig->{$configvariable})) {
-                if ( $authconfig->{$configvariable} === 'locked'
-                    || ($authconfig->{$configvariable} === 'unlockedifempty' && !empty($user->$field)) ) {
+            if (isset($authplugin->config->{$configvariable})) {
+                if ( $authplugin->config->{$configvariable} === 'locked'
+                    or ($authplugin->config->{$configvariable} === 'unlockedifempty' and !empty($user->$field))) {
                    echo "eval('document.form.$field.disabled=true');\n";
                 }
             }
@@ -412,7 +419,7 @@ function find_form_errors(&$user, &$usernew, &$err, &$um) {
         if (empty($usernew->username)) {
             $err["username"] = get_string("missingusername");
 
-        } else if (record_exists("user", "username", $usernew->username) and $user->username == "changeme") {
+        } else if (record_exists("user", "username", $usernew->username, 'mnethostid', $CFG->mnet_localhost_id) and $user->username == "changeme") {
             $err["username"] = get_string("usernameexists");
 
         } else {
@@ -424,9 +431,10 @@ function find_form_errors(&$user, &$usernew, &$err, &$um) {
             }
         }
 
-        if (empty($usernew->newpassword) and empty($user->password) and is_internal_auth() )
+        // TODO: is_internal_auth() - what, the global auth? the user auth?
+        if (empty($usernew->newpassword) and empty($user->password) and is_internal_auth()) {
             $err["newpassword"] = get_string("missingpassword");
-
+        }
         if (($usernew->newpassword == "admin") or ($user->password == md5("admin") and empty($usernew->newpassword)) ) {
             $err["newpassword"] = get_string("unsafepassword");
         }
index 3afac25fdc4df8ca8423b7e15310d36bade5e91d..a33dff2e986f8fe232d5c9b8a49ff948ec64038a 100644 (file)
         if (($mainadmin = get_admin()) === false) {
             $mainadmin->id = 0; /// Weird - no primary admin!
         }
-        if ((!empty($USER->id) and ($USER->id == $user->id) and !isguest()) or
+
+        if (is_mnet_remote_user($user)) {
+            // cannot edit remote users
+        }
+        else if ((!empty($USER->id) and ($USER->id == $user->id) and !isguest()) or
             (has_capability('moodle/user:editprofile', $personalcontext) and ($user->id != $mainadmin->id)) ) {
 
             if(empty($CFG->loginhttps)) {
index 3c490bce7eafd26ca329416650cea29ba2a753dd..1356812ea01b1cd017f3fc99a835bd8e38c8a261 100644 (file)
     $showroles = 1;
     include('tabs.php');
 
+    if (is_mnet_remote_user($user)) {
+        echo "<p class=\"errorboxcontent\">This profile is for a remote user from another Moodle system. <br>\n";
+        $remotehost = get_record('mnet_host', 'id', $user->mnethostid);
+        echo "Remote Moodle: <a href=\"{$remotehost->wwwroot}/user/edit.php\">{$remotehost->name}</a> (click here to edit your profile on the remote server) </p>\n";
+    }
+
     echo "<table width=\"80%\" align=\"center\" border=\"0\" cellspacing=\"0\" class=\"userinfobox\">";
     echo "<tr>";
     echo "<td width=\"100\" valign=\"top\" class=\"side\">";
     echo "</td></tr></table>";
 
     $internalpassword = false;
-    if (is_internal_auth($user->auth) or (!empty($CFG->{'auth_'.$user->auth.'_stdchangepassword'}))) {
+    $userauth = get_auth_plugin($user->auth);
+    if (method_exists($userauth, 'can_change_password') and $userauth->can_change_password()) {
         if (empty($CFG->loginhttps)) {
             $internalpassword = "$CFG->wwwroot/login/change_password.php";
         } else {
                 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
             }
             echo "</form></td>";
-        } else if ( strlen($CFG->{'auth_'.$user->auth.'_changepasswordurl'}) > 1 ) {
-            echo "<td nowrap=\"nowrap\"><form action=\"".$CFG->{'auth_'.$user->auth.'_changepasswordurl'}."\" method=\"get\">";
+        } elseif ( method_exists($userauth, 'change_password_url') and strlen($userauth->change_password_url())) {
+            echo "<td nowrap=\"nowrap\"><form action=\"".$userauth->change_password_url()."\" method=\"get\">";
             echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
             echo "</form></td>";
         }