3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
23 * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require('../config.php');
28 require_once($CFG->dirroot
. '/user/editlib.php');
29 require_once($CFG->libdir
. '/authlib.php');
30 require_once('lib.php');
32 if (!$authplugin = signup_is_enabled()) {
33 print_error('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
36 $PAGE->set_url('/login/signup.php');
37 $PAGE->set_context(context_system
::instance());
39 // If wantsurl is empty or /login/signup.php, override wanted URL.
40 // We do not want to end up here again if user clicks "Login".
41 if (empty($SESSION->wantsurl
)) {
42 $SESSION->wantsurl
= $CFG->wwwroot
. '/';
44 $wantsurl = new moodle_url($SESSION->wantsurl
);
45 if ($PAGE->url
->compare($wantsurl, URL_MATCH_BASE
)) {
46 $SESSION->wantsurl
= $CFG->wwwroot
. '/';
50 if (isloggedin() and !isguestuser()) {
51 // Prevent signing up when already logged in.
52 echo $OUTPUT->header();
53 echo $OUTPUT->box_start();
54 $logout = new single_button(new moodle_url('/login/logout.php',
55 array('sesskey' => sesskey(), 'loginpage' => 1)), get_string('logout'), 'post');
56 $continue = new single_button(new moodle_url('/'), get_string('cancel'), 'get');
57 echo $OUTPUT->confirm(get_string('cannotsignup', 'error', fullname($USER)), $logout, $continue);
58 echo $OUTPUT->box_end();
59 echo $OUTPUT->footer();
63 // If verification of age and location (digital minor check) is enabled.
64 if (\core_auth\digital_consent
::is_age_digital_consent_verification_enabled()) {
65 $cache = cache
::make('core', 'presignup');
66 $isminor = $cache->get('isminor');
67 if ($isminor === false) {
68 // The verification of age and location (minor) has not been done.
69 redirect(new moodle_url('/login/verify_age_location.php'));
70 } else if ($isminor === 'yes') {
71 // The user that attempts to sign up is a digital minor.
72 redirect(new moodle_url('/login/digital_minor.php'));
76 // Plugins can create pre sign up requests.
77 // Can be used to force additional actions before sign up such as acceptance of policies, validations, etc.
78 core_login_pre_signup_requests();
80 $mform_signup = $authplugin->signup_form();
82 if ($mform_signup->is_cancelled()) {
83 redirect(get_login_url());
85 } else if ($user = $mform_signup->get_data()) {
86 // Add missing required fields.
87 $user = signup_setup_new_user($user);
89 $authplugin->user_signup($user, true); // prints notice and link to login/index.php
94 $newaccount = get_string('newaccount');
95 $login = get_string('login');
97 $PAGE->navbar
->add($login);
98 $PAGE->navbar
->add($newaccount);
100 $PAGE->set_pagelayout('login');
101 $PAGE->set_title($newaccount);
102 $PAGE->set_heading($SITE->fullname
);
104 echo $OUTPUT->header();
106 if ($mform_signup instanceof renderable
) {
107 // Try and use the renderer from the auth plugin if it exists.
109 $renderer = $PAGE->get_renderer('auth_' . $authplugin->authtype
);
110 } catch (coding_exception
$ce) {
111 // Fall back on the general renderer.
114 echo $renderer->render($mform_signup);
116 // Fall back for auth plugins not using renderables.
117 $mform_signup->display();
119 echo $OUTPUT->footer();