mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-56739 auth: Support launching the app upon user confirm
This commit is contained in:
parent
b0f00b3166
commit
b5f3e90e1c
2 changed files with 34 additions and 6 deletions
|
@ -31,6 +31,7 @@ require_once($CFG->libdir . '/externallib.php');
|
|||
$serviceshortname = required_param('service', PARAM_ALPHANUMEXT);
|
||||
$passport = required_param('passport', PARAM_RAW); // Passport send from the app to validate the response URL.
|
||||
$urlscheme = optional_param('urlscheme', 'moodlemobile', PARAM_NOTAGS); // The URL scheme the app supports.
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL); // If we are being redirected after user confirmation.
|
||||
|
||||
// Check web services enabled.
|
||||
if (!$CFG->enablewebservices) {
|
||||
|
@ -39,7 +40,8 @@ if (!$CFG->enablewebservices) {
|
|||
|
||||
// Check if the plugin is properly configured.
|
||||
$typeoflogin = get_config('tool_mobile', 'typeoflogin');
|
||||
if ($typeoflogin != tool_mobile\api::LOGIN_VIA_BROWSER and
|
||||
if (empty($SESSION->justloggedin) and
|
||||
$typeoflogin != tool_mobile\api::LOGIN_VIA_BROWSER and
|
||||
$typeoflogin != tool_mobile\api::LOGIN_VIA_EMBEDDED_BROWSER) {
|
||||
throw new moodle_exception('pluginnotenabledorconfigured', 'tool_mobile');
|
||||
}
|
||||
|
@ -87,11 +89,24 @@ if (!empty($forcedurlscheme)) {
|
|||
$location = "$urlscheme://token=$apptoken";
|
||||
|
||||
// For iOS 10 onwards, we have to simulate a user click.
|
||||
if (core_useragent::is_ios()) {
|
||||
$PAGE->set_context(null);
|
||||
// If we come from the confirmation page, we should display a nicer page.
|
||||
$isios = core_useragent::is_ios();
|
||||
if ($confirmed or $isios) {
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
$PAGE->set_url('/local/mobile/launch.php', array('service' => $serviceshortname, 'passport' => $passport, 'urlscheme' => $urlscheme));
|
||||
|
||||
echo $OUTPUT->header();
|
||||
if ($confirmed) {
|
||||
$confirmedstr = get_string('confirmed');
|
||||
$PAGE->navbar->add($confirmedstr);
|
||||
$PAGE->set_title($confirmedstr);
|
||||
echo $OUTPUT->notification($confirmedstr, \core\output\notification::NOTIFY_SUCCESS);
|
||||
echo $OUTPUT->box_start('generalbox centerpara boxwidthnormal boxaligncenter');
|
||||
echo $OUTPUT->single_button(new moodle_url('/course/'), get_string('courses'));
|
||||
echo $OUTPUT->box_end();
|
||||
}
|
||||
|
||||
$notice = get_string('clickheretolaunchtheapp', 'tool_mobile');
|
||||
echo html_writer::link($location, $notice, array('id' => 'launchapp'));
|
||||
echo html_writer::script(
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue