commit 889a6b8f2aa991c612466a1fb231c0ae44fec8e0 Author: Jay Knight Date: Tue Aug 17 09:19:18 2010 -0500 MDL-23489 Let auth plugins handle profile editing diff --git a/lang/en/auth.php b/lang/en/auth.php index decfae4..072dc59 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -96,6 +96,7 @@ $string['locked'] = 'Locked'; $string['md5'] = 'MD5 hash'; $string['nopasswordchange'] = 'Password can not be changed'; $string['nopasswordchangeforced'] = 'You cannot proceed without changing your password, however there is no available page for changing it. Please contact your Moodle Administrator.'; +$string['noprofileedit'] = 'Profile can not be edited'; $string['ntlmsso_attempting'] = 'Attempting Single Sign On via NTLM...'; $string['ntlmsso_failed'] = 'Auto-login failed, try the normal login page...'; $string['ntlmsso_isdisabled'] = 'NTLM SSO is disabled.'; diff --git a/lib/authlib.php b/lib/authlib.php index 48d1c37..3b0f564 100644 --- a/lib/authlib.php +++ b/lib/authlib.php @@ -147,6 +147,31 @@ class auth_plugin_base { } /** + * Returns true if this authentication plugin can edit the users' + * profile. + * + * @return bool + */ + function can_edit_profile() { + //override if needed + return false; + } + + /** + * Returns the URL for editing the users' profile, or empty if the default + * URL can be used. + * + * This method is used if can_edit_profile() returns true. + * This method is called only when user is logged in, it may use global $USER. + * + * @return string + */ + function edit_profile_url() { + //override if needed + return ''; + } + + /** * Returns true if this authentication plugin is "internal" (which means that * Moodle stores the users' passwords and other details in the local Moodle * database). diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 6432996..49ec811 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -3260,8 +3260,16 @@ class settings_navigation extends navigation_node { $url = new moodle_url('/user/editadvanced.php', array('id'=>$user->id, 'course'=>$course->id)); $usersetting->add(get_string('editmyprofile'), $url, self::TYPE_SETTING); } else if ((has_capability('moodle/user:editprofile', $usercontext) && !is_siteadmin($user)) || ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext))) { - $url = new moodle_url('/user/edit.php', array('id'=>$user->id, 'course'=>$course->id)); - $usersetting->add(get_string('editmyprofile'), $url, self::TYPE_SETTING); + if (!empty($user->auth)) { + $userauth = get_auth_plugin($user->auth); + if ($userauth->can_edit_profile()) { + $url = $userauth->edit_profile_url(); + if (empty($url)) { + $url = new moodle_url('/user/edit.php', array('id'=>$user->id, 'course'=>$course->id)); + } + $usersetting->add(get_string('editmyprofile'), $url, self::TYPE_SETTING); + } + } } } diff --git a/user/edit.php b/user/edit.php index 32fa072..2b296a0 100644 --- a/user/edit.php +++ b/user/edit.php @@ -86,6 +86,18 @@ if (is_mnet_remote_user($user)) { redirect($CFG->wwwroot . "/user/view.php?course={$course->id}"); } +// load the appropriate auth plugin +$userauth = get_auth_plugin($user->auth); + +if (!$userauth->can_edit_profile()) { + print_error('noprofileedit', 'auth'); +} + +if ($editurl = $userauth->edit_profile_url()) { + // this internal scrip not used + redirect($editurl); +} + if ($course->id == SITEID) { $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context } else {