Merge branch 'MDL-60410_master' of git://github.com/dmonllao/moodle
[moodle.git] / login / signup.php
blob03321e459e604a387394825161fc46e0fe888ff3
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
9 //
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/>.
18 /**
19 * user signup page.
21 * @package core
22 * @subpackage auth
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');
31 if (!$authplugin = signup_is_enabled()) {
32 print_error('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
35 //HTTPS is required in this page when $CFG->loginhttps enabled
36 $PAGE->https_required();
38 $PAGE->set_url('/login/signup.php');
39 $PAGE->set_context(context_system::instance());
41 // If wantsurl is empty or /login/signup.php, override wanted URL.
42 // We do not want to end up here again if user clicks "Login".
43 if (empty($SESSION->wantsurl)) {
44 $SESSION->wantsurl = $CFG->wwwroot . '/';
45 } else {
46 $wantsurl = new moodle_url($SESSION->wantsurl);
47 if ($PAGE->url->compare($wantsurl, URL_MATCH_BASE)) {
48 $SESSION->wantsurl = $CFG->wwwroot . '/';
52 if (isloggedin() and !isguestuser()) {
53 // Prevent signing up when already logged in.
54 echo $OUTPUT->header();
55 echo $OUTPUT->box_start();
56 $logout = new single_button(new moodle_url($CFG->httpswwwroot . '/login/logout.php',
57 array('sesskey' => sesskey(), 'loginpage' => 1)), get_string('logout'), 'post');
58 $continue = new single_button(new moodle_url('/'), get_string('cancel'), 'get');
59 echo $OUTPUT->confirm(get_string('cannotsignup', 'error', fullname($USER)), $logout, $continue);
60 echo $OUTPUT->box_end();
61 echo $OUTPUT->footer();
62 exit;
65 $mform_signup = $authplugin->signup_form();
67 if ($mform_signup->is_cancelled()) {
68 redirect(get_login_url());
70 } else if ($user = $mform_signup->get_data()) {
71 // Add missing required fields.
72 $user = signup_setup_new_user($user);
74 $authplugin->user_signup($user, true); // prints notice and link to login/index.php
75 exit; //never reached
78 // make sure we really are on the https page when https login required
79 $PAGE->verify_https_required();
82 $newaccount = get_string('newaccount');
83 $login = get_string('login');
85 $PAGE->navbar->add($login);
86 $PAGE->navbar->add($newaccount);
88 $PAGE->set_pagelayout('login');
89 $PAGE->set_title($newaccount);
90 $PAGE->set_heading($SITE->fullname);
92 echo $OUTPUT->header();
94 if ($mform_signup instanceof renderable) {
95 // Try and use the renderer from the auth plugin if it exists.
96 try {
97 $renderer = $PAGE->get_renderer('auth_' . $authplugin->authtype);
98 } catch (coding_exception $ce) {
99 // Fall back on the general renderer.
100 $renderer = $OUTPUT;
102 echo $renderer->render($mform_signup);
103 } else {
104 // Fall back for auth plugins not using renderables.
105 $mform_signup->display();
107 echo $OUTPUT->footer();