MDL-56739 auth: Support launching the app upon user confirm

This commit is contained in:
Juan Leyva 2016-11-03 21:40:33 +00:00
parent b0f00b3166
commit b5f3e90e1c
2 changed files with 34 additions and 6 deletions

View file

@ -202,7 +202,8 @@ class auth_email_external extends external_api {
'value' => new external_value(PARAM_RAW, 'Custom field value, can be an encoded json if required')
)
), 'User custom fields (also known as user profile fields)', VALUE_DEFAULT, array()
)
),
'redirect' => new external_value(PARAM_URL, 'Redirect the user to this url after confirmation.', VALUE_DEFAULT, ''),
)
);
}
@ -220,13 +221,15 @@ class auth_email_external extends external_api {
* @param string $recaptchachallengehash recaptcha challenge hash
* @param string $recaptcharesponse recaptcha response
* @param array $customprofilefields user custom fields (also known as user profile fields)
* @param string $redirect Url to redirect the user after confirmation
* @return array settings and possible warnings
* @since Moodle 3.2
* @throws moodle_exception
* @throws invalid_parameter_exception
*/
public static function signup_user($username, $password, $firstname, $lastname, $email, $city = '', $country = '',
$recaptchachallengehash = '', $recaptcharesponse = '', $customprofilefields = array()) {
$recaptchachallengehash = '', $recaptcharesponse = '', $customprofilefields = array(),
$redirect = '') {
global $CFG, $PAGE;
$warnings = array();
@ -243,6 +246,7 @@ class auth_email_external extends external_api {
'recaptchachallengehash' => $recaptchachallengehash,
'recaptcharesponse' => $recaptcharesponse,
'customprofilefields' => $customprofilefields,
'redirect' => $redirect,
)
);
@ -324,7 +328,16 @@ class auth_email_external extends external_api {
$user = signup_setup_new_user((object) $data);
$authplugin = get_auth_plugin('email');
$authplugin->user_signup($user, false);
// Check if we should redirect the user once the user is confirmed.
$confirmationurl = null;
if (!empty($params['redirect'])) {
// Pass via moodle_url to fix thinks like admin links.
$redirect = new moodle_url($params['redirect']);
$confirmationurl = new moodle_url('/login/confirm.php', array('redirect' => $redirect->out()));
}
$authplugin->user_signup_with_confirmation($user, false, $confirmationurl);
$result = array(
'success' => true,