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 "\" />";
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=\"";
}
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 {
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";
}
}
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 {
}
}
- 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");
}
$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>";
}