Merge branch 'wip-MDL-57234-master' of https://github.com/Beedell/moodle
[moodle.git] / login / signup.php
blobad7d9454246df34e9d53bb3a185bf30eccaa5943
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 // Try to prevent searching for sites that allow sign-up.
32 if (!isset($CFG->additionalhtmlhead)) {
33 $CFG->additionalhtmlhead = '';
35 $CFG->additionalhtmlhead .= '<meta name="robots" content="noindex" />';
37 if (!$authplugin = signup_is_enabled()) {
38 print_error('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
41 //HTTPS is required in this page when $CFG->loginhttps enabled
42 $PAGE->https_required();
44 $PAGE->set_url('/login/signup.php');
45 $PAGE->set_context(context_system::instance());
47 // Override wanted URL, we do not want to end up here again if user clicks "Login".
48 $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($CFG->httpswwwroot . '/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();
60 exit;
63 $mform_signup = $authplugin->signup_form();
65 if ($mform_signup->is_cancelled()) {
66 redirect(get_login_url());
68 } else if ($user = $mform_signup->get_data()) {
69 // Add missing required fields.
70 $user = signup_setup_new_user($user);
72 $authplugin->user_signup($user, true); // prints notice and link to login/index.php
73 exit; //never reached
76 // make sure we really are on the https page when https login required
77 $PAGE->verify_https_required();
80 $newaccount = get_string('newaccount');
81 $login = get_string('login');
83 $PAGE->navbar->add($login);
84 $PAGE->navbar->add($newaccount);
86 $PAGE->set_pagelayout('login');
87 $PAGE->set_title($newaccount);
88 $PAGE->set_heading($SITE->fullname);
90 echo $OUTPUT->header();
92 echo $OUTPUT->render($mform_signup);
93 echo $OUTPUT->footer();