From d6a25bc49abe507d134d97e4c3ef7e78b26f8458 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Thu, 3 Nov 2016 21:18:18 +0000 Subject: [PATCH] MDL-56739 auth: Support custom confirmation URL --- auth/email/auth.php | 22 ++++++++++++++++++++-- auth/upgrade.txt | 2 ++ lib/moodlelib.php | 10 ++++++++-- lib/upgrade.txt | 1 + 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/auth/email/auth.php b/auth/email/auth.php index ffa0e9126d3..e9c1da1820a 100644 --- a/auth/email/auth.php +++ b/auth/email/auth.php @@ -95,6 +95,24 @@ class auth_plugin_email extends auth_plugin_base { * @param boolean $notify print notice with link and terminate */ function user_signup($user, $notify=true) { + // Standard signup, without custom confirmatinurl. + return $this->user_signup_with_confirmation($user, $notify); + } + + /** + * Sign up a new user ready for confirmation. + * + * Password is passed in plaintext. + * A custom confirmationurl could be used. + * + * @param object $user new user object + * @param boolean $notify print notice with link and terminate + * @param string $confirmationurl user confirmation URL + * @return boolean true if everything well ok and $notify is set to true + * @throws moodle_exception + * @since Moodle 3.2 + */ + public function user_signup_with_confirmation($user, $notify=true, $confirmationurl = null) { global $CFG, $DB; require_once($CFG->dirroot.'/user/profile/lib.php'); require_once($CFG->dirroot.'/user/lib.php'); @@ -115,8 +133,8 @@ class auth_plugin_email extends auth_plugin_base { // Trigger event. \core\event\user_created::create_from_userid($user->id)->trigger(); - if (! send_confirmation_email($user)) { - print_error('auth_emailnoemail','auth_email'); + if (! send_confirmation_email($user, $confirmationurl)) { + print_error('auth_emailnoemail', 'auth_email'); } if ($notify) { diff --git a/auth/upgrade.txt b/auth/upgrade.txt index d339ea05513..8a1dc21d94b 100644 --- a/auth/upgrade.txt +++ b/auth/upgrade.txt @@ -7,6 +7,8 @@ information provided here is intended especially for developers. This can be used to modify the user object before any authentication errors are raised. * The block_login now displays the loginpage_idp_list() links as well as main login page. * The authentication plugin auth_radius has been moved to https://github.com/moodlehq/moodle-auth_radius +* New auth_email::user_signup_with_confirmation() method has a new optional parameter $confirmationurl to provide a different + confirmation URL. === 3.0 === diff --git a/lib/moodlelib.php b/lib/moodlelib.php index f1451d598c2..ecff98b1245 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -6134,9 +6134,10 @@ function reset_password_and_mail($user) { * Send email to specified user with confirmation text and activation link. * * @param stdClass $user A {@link $USER} object + * @param string $confirmationurl user confirmation URL * @return bool Returns true if mail was sent OK and false if there was an error. */ -function send_confirmation_email($user) { +function send_confirmation_email($user, $confirmationurl = null) { global $CFG; $site = get_site(); @@ -6151,7 +6152,12 @@ function send_confirmation_email($user) { $username = urlencode($user->username); $username = str_replace('.', '%2E', $username); // Prevent problems with trailing dots. - $data->link = $CFG->wwwroot .'/login/confirm.php?data='. $user->secret .'/'. $username; + if (empty($confirmationurl)) { + $confirmationurl = '/login/confirm.php'; + } + $confirmationurl = new moodle_url($confirmationurl, array('data' => $user->secret .'/'. $username)); + $data->link = $confirmationurl->out(false); + $message = get_string('emailconfirmation', '', $data); $messagehtml = text_to_html(get_string('emailconfirmation', '', $data), false, false, true); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index b644a5aa48c..64d4b88c9de 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -130,6 +130,7 @@ information provided here is intended especially for developers. message_sent::create_from_ids() will show a debugging notice if the \core\message\message being sent is missing the courseid property, defaulting to SITEID automatically. In Moodle 3.6 (MDL-55449) courseid will be fully mandatory for all messages sent. +* The send_confirmation_email() function has a new optional parameter $confirmationurl to provide a different confirmation URL. === 3.1 === -- 2.11.4.GIT