MDL-56739 auth: Support custom confirmation URL

This commit is contained in:
Juan Leyva 2016-11-03 21:18:18 +00:00
parent 258d07d37e
commit d6a25bc49a
4 changed files with 31 additions and 4 deletions

View File

@ -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) {

View File

@ -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 ===

View File

@ -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);

View File

@ -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 ===