From: martinlanghoff Date: Thu, 4 Jan 2007 03:01:30 +0000 (+0000) Subject: mnet: user/* now handles remote users and multi-auth X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=56f52742322636ead2ae0f8700e5c1f876cd2720;p=moodle.git mnet: user/* now handles remote users and multi-auth --- diff --git a/user/edit.html b/user/edit.html index 86878fc220..4b9fc4ae56 100644 --- a/user/edit.html +++ b/user/edit.html @@ -28,9 +28,10 @@ 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 ''; echo ''.get_string('username').':'; - if ($adminself || is_internal_auth($user->auth) ){ + if ($adminself or $userauth->is_internal()) { echo "username); echo "\" />"; @@ -58,7 +59,7 @@ if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SI echo "\n"; } - if ($adminself || is_internal_auth($user->auth) || (!empty($CFG->{'auth_'.$user->auth.'_stdchangepassword'}))) { + if ($adminself or $userauth->can_change_password()) { echo ''; echo ''.get_string('newpassword').':'; echo ""; echo "\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 { diff --git a/user/edit.php b/user/edit.php index 6671fde741..e38fb92dcb 100644 --- a/user/edit.php +++ b/user/edit.php @@ -35,6 +35,11 @@ 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()) { @@ -59,11 +64,15 @@ // 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); } @@ -157,14 +166,13 @@ // 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); } @@ -205,9 +213,10 @@ 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.'); } @@ -233,9 +242,9 @@ $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. @@ -371,13 +380,11 @@ echo '