Skip to content

Commit

Permalink
MDL-23489 auth plugins can specify own edit profile url - patch submi…
Browse files Browse the repository at this point in the history
…tted by Jay Knight + tweaking change password url to use new moodle_url at the same time, it is backwards compatible, custom plugins may still use string url for now
  • Loading branch information
skodak committed Aug 18, 2010
1 parent 84deffa commit 99f9f85
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 30 deletions.
6 changes: 3 additions & 3 deletions auth/cas/auth.php
Expand Up @@ -3,7 +3,7 @@
/**
* @author Martin Dougiamas
* @author Jerome GUTIERREZ
* @author Iñaki Arenaza
* @author I�aki Arenaza
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package moodle multiauth
*
Expand Down Expand Up @@ -209,10 +209,10 @@ function config_form($config, $err, $user_fields) {
* Returns the URL for changing the user's pw, or empty if the default can
* be used.
*
* @return string
* @return moodle_url
*/
function change_password_url() {
return '';
return null;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions auth/db/auth.php
Expand Up @@ -597,15 +597,15 @@ function can_change_password() {
* Returns the URL for changing the user's pw, or empty if the default can
* be used.
*
* @return string
* @return moodle_url
*/
function change_password_url() {
if ($this->config->passtype == 'internal') {
// standard form
return '';
return null;
} else {
// use custom url
return $this->config->changepasswordurl;
return new moodle_url($this->config->changepasswordurl);
}
}

Expand Down
4 changes: 2 additions & 2 deletions auth/email/auth.php
Expand Up @@ -173,10 +173,10 @@ function can_change_password() {
* Returns the URL for changing the user's pw, or empty if the default can
* be used.
*
* @return mixed
* @return moodle_url
*/
function change_password_url() {
return ''; // use dafult internal method
return null; // use default internal method
}

/**
Expand Down
4 changes: 2 additions & 2 deletions auth/imap/auth.php
Expand Up @@ -108,10 +108,10 @@ function can_change_password() {
* Returns the URL for changing the user's pw, or empty if the default can
* be used.
*
* @return string
* @return moodle_url
*/
function change_password_url() {
return $this->config->changepasswordurl;
return new moodle_url($this->config->changepasswordurl);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions auth/ldap/auth.php
Expand Up @@ -2,7 +2,7 @@

/**
* @author Martin Dougiamas
* @author Iñaki Arenaza
* @author I�aki Arenaza
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package moodle multiauth
*
Expand Down Expand Up @@ -1098,7 +1098,7 @@ function user_update($olduser, $newuser) {
if (empty($user_entry)) {
$attribs = join (', ', $search_attribs);
error_log($this->errorlogtag.get_string('updateusernotfound', 'auth_ldap',
array('userdn'=>$user_dn,
array('userdn'=>$user_dn,
'attribs'=>$attribs)));
return false; // old user not found!
} else if (count($user_entry) > 1) {
Expand Down Expand Up @@ -1493,13 +1493,13 @@ function can_change_password() {
* Returns the URL for changing the user's password, or empty if the default can
* be used.
*
* @return string url
* @return moodle_url
*/
function change_password_url() {
if (empty($this->config->stdchangepassword)) {
return $this->config->changepasswordurl;
return new moodle_url($this->config->changepasswordurl);
} else {
return '';
return null;
}
}

Expand Down
4 changes: 2 additions & 2 deletions auth/manual/auth.php
Expand Up @@ -89,10 +89,10 @@ function can_change_password() {
* Returns the URL for changing the user's pw, or empty if the default can
* be used.
*
* @return string
* @return moodle_url
*/
function change_password_url() {
return '';
return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions auth/mnet/auth.php
Expand Up @@ -565,10 +565,10 @@ function can_change_password() {
* Returns the URL for changing the user's pw, or false if the default can
* be used.
*
* @return string
* @return moodle_url
*/
function change_password_url() {
return '';
return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions auth/none/auth.php
Expand Up @@ -89,10 +89,10 @@ function can_change_password() {
* Returns the URL for changing the user's pw, or empty if the default can
* be used.
*
* @return string
* @return moodle_url
*/
function change_password_url() {
return '';
return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions auth/pop3/auth.php
Expand Up @@ -108,10 +108,10 @@ function can_change_password() {
* Returns the URL for changing the user's pw, or false if the default can
* be used.
*
* @return bool
* @return moodle_url
*/
function change_password_url() {
return $this->config->changepasswordurl;
return new moodle_url($this->config->changepasswordurl);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions auth/webservice/auth.php
Expand Up @@ -111,10 +111,10 @@ function can_change_password() {
* Returns the URL for changing the user's pw, or empty if the default can
* be used.
*
* @return string
* @return moodle_url
*/
function change_password_url() {
return '';
return null;
}

/**
Expand Down
1 change: 1 addition & 0 deletions lang/en/auth.php
Expand Up @@ -96,6 +96,7 @@
$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.';
Expand Down
29 changes: 27 additions & 2 deletions lib/authlib.php
Expand Up @@ -139,11 +139,36 @@ function can_change_password() {
* This method is used if can_change_password() returns true.
* This method is called only when user is logged in, it may use global $USER.
*
* @return string
* @return moodle_url url of the profile page or null if standard used
*/
function change_password_url() {
//override if needed
return '';
return null;
}

/**
* Returns true if this authentication plugin can edit the users'
* profile.
*
* @return bool
*/
function can_edit_profile() {
//override if needed
return true;
}

/**
* 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 moodle_url url of the profile page or null if standard used
*/
function edit_profile_url() {
//override if needed
return null;
}

/**
Expand Down
12 changes: 10 additions & 2 deletions lib/navigationlib.php
Expand Up @@ -3260,8 +3260,16 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr
$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);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion login/index.php
Expand Up @@ -194,7 +194,7 @@
if (!empty($userauth->config->expiration) and $userauth->config->expiration == 1) {
if ($userauth->can_change_password()) {
$passwordchangeurl = $userauth->change_password_url();
if(!$passwordchangeurl) {
if (!$passwordchangeurl) {
$passwordchangeurl = $CFG->httpswwwroot.'/login/change_password.php';
}
} else {
Expand Down
12 changes: 12 additions & 0 deletions user/edit.php
Expand Up @@ -86,6 +86,18 @@
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 script not used
redirect($editurl);
}

if ($course->id == SITEID) {
$coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
} else {
Expand Down

0 comments on commit 99f9f85

Please sign in to comment.