MDL-57759 mod_lesson: New settings for allowing offline attempts
[moodle.git] / login / signup.php
blobe14518006cd6691de9faf58d91d53030eda89135
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 // If wantsurl is empty or /login/signup.php, override wanted URL.
48 // We do not want to end up here again if user clicks "Login".
49 if (empty($SESSION->wantsurl)) {
50 $SESSION->wantsurl = $CFG->wwwroot . '/';
51 } else {
52 $wantsurl = new moodle_url($SESSION->wantsurl);
53 if ($PAGE->url->compare($wantsurl, URL_MATCH_BASE)) {
54 $SESSION->wantsurl = $CFG->wwwroot . '/';
58 if (isloggedin() and !isguestuser()) {
59 // Prevent signing up when already logged in.
60 echo $OUTPUT->header();
61 echo $OUTPUT->box_start();
62 $logout = new single_button(new moodle_url($CFG->httpswwwroot . '/login/logout.php',
63 array('sesskey' => sesskey(), 'loginpage' => 1)), get_string('logout'), 'post');
64 $continue = new single_button(new moodle_url('/'), get_string('cancel'), 'get');
65 echo $OUTPUT->confirm(get_string('cannotsignup', 'error', fullname($USER)), $logout, $continue);
66 echo $OUTPUT->box_end();
67 echo $OUTPUT->footer();
68 exit;
71 $mform_signup = $authplugin->signup_form();
73 if ($mform_signup->is_cancelled()) {
74 redirect(get_login_url());
76 } else if ($user = $mform_signup->get_data()) {
77 // Add missing required fields.
78 $user = signup_setup_new_user($user);
80 $authplugin->user_signup($user, true); // prints notice and link to login/index.php
81 exit; //never reached
84 // make sure we really are on the https page when https login required
85 $PAGE->verify_https_required();
88 $newaccount = get_string('newaccount');
89 $login = get_string('login');
91 $PAGE->navbar->add($login);
92 $PAGE->navbar->add($newaccount);
94 $PAGE->set_pagelayout('login');
95 $PAGE->set_title($newaccount);
96 $PAGE->set_heading($SITE->fullname);
98 echo $OUTPUT->header();
100 echo $OUTPUT->render($mform_signup);
101 echo $OUTPUT->footer();