login MDL-19800 Upgrade deprecated calls and added set_url calls

This commit is contained in:
samhemelryk 2009-09-29 03:55:09 +00:00
parent eb5334ff48
commit 8570cff01f
7 changed files with 592 additions and 497 deletions

View file

@ -1,69 +1,98 @@
<?PHP // $Id$ <?php
require_once('../config.php'); // This file is part of Moodle - http://moodle.org/
require_once('change_password_form.php'); //
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
$id = optional_param('id', SITEID, PARAM_INT); // current course /**
* This file is part of the login section Moodle
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package login
*/
$strparticipants = get_string('participants'); require_once('../config.php');
require_once('change_password_form.php');
//HTTPS is potentially required in this page $id = optional_param('id', SITEID, PARAM_INT); // current course
httpsrequired();
$systemcontext = get_context_instance(CONTEXT_SYSTEM); $url = new moodle_url($CFG->wwwroot.'/login/change_password.php');
if ($id !== SITEID) {
$url->param('id', $id);
}
$PAGE->set_url($url);
if (!$course = $DB->get_record('course', array('id'=>$id))) { $strparticipants = get_string('participants');
//HTTPS is potentially required in this page
httpsrequired();
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid'); print_error('invalidcourseid');
} }
// require proper login; guest user can not change password // require proper login; guest user can not change password
if (empty($USER->id) or isguestuser()) { if (empty($USER->id) or isguestuser()) {
if (empty($SESSION->wantsurl)) { if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = $CFG->httpswwwroot.'/login/change_password.php'; $SESSION->wantsurl = $CFG->httpswwwroot.'/login/change_password.php';
} }
redirect(get_login_url()); redirect(get_login_url());
} }
// do not require change own password cap if change forced // do not require change own password cap if change forced
if (!get_user_preferences('auth_forcepasswordchange', false)) { if (!get_user_preferences('auth_forcepasswordchange', false)) {
require_login(); require_login();
require_capability('moodle/user:changeownpassword', $systemcontext); require_capability('moodle/user:changeownpassword', $systemcontext);
} }
// do not allow "Logged in as" users to change any passwords // do not allow "Logged in as" users to change any passwords
if (session_is_loggedinas()) { if (session_is_loggedinas()) {
print_error('cannotcallscript'); print_error('cannotcallscript');
} }
if (is_mnet_remote_user($USER)) { if (is_mnet_remote_user($USER)) {
$message = get_string('usercannotchangepassword', 'mnet'); $message = get_string('usercannotchangepassword', 'mnet');
if ($idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) { if ($idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) {
$message .= get_string('userchangepasswordlink', 'mnet', $idprovider); $message .= get_string('userchangepasswordlink', 'mnet', $idprovider);
} }
print_error('userchangepasswordlink', 'mnet', '', $message); print_error('userchangepasswordlink', 'mnet', '', $message);
} }
// load the appropriate auth plugin // load the appropriate auth plugin
$userauth = get_auth_plugin($USER->auth); $userauth = get_auth_plugin($USER->auth);
if (!$userauth->can_change_password()) { if (!$userauth->can_change_password()) {
print_error('nopasswordchange', 'auth'); print_error('nopasswordchange', 'auth');
} }
if ($changeurl = $userauth->change_password_url()) { if ($changeurl = $userauth->change_password_url()) {
// this internal scrip not used // this internal scrip not used
redirect($changeurl); redirect($changeurl);
} }
$mform = new login_change_password_form(); $mform = new login_change_password_form();
$mform->set_data(array('id'=>$course->id)); $mform->set_data(array('id'=>$course->id));
$navlinks = array(); $navlinks = array();
$navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'misc'); $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'misc');
if ($mform->is_cancelled()) { if ($mform->is_cancelled()) {
redirect($CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$course->id); redirect($CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$course->id);
} else if ($data = $mform->get_data()) { } else if ($data = $mform->get_data()) {
if (!$userauth->user_update_password($USER, $data->newpassword1)) { if (!$userauth->user_update_password($USER, $data->newpassword1)) {
print_error('errorpasswordupdate', 'auth'); print_error('errorpasswordupdate', 'auth');
@ -94,23 +123,23 @@
echo $OUTPUT->footer(); echo $OUTPUT->footer();
exit; exit;
} }
$strchangepassword = get_string('changepassword'); $strchangepassword = get_string('changepassword');
$fullname = fullname($USER, true); $fullname = fullname($USER, true);
$PAGE->navbar->add($fullname, new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$USER->id, 'course'=>$course->id))); $PAGE->navbar->add($fullname, new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$USER->id, 'course'=>$course->id)));
$PAGE->navbar->add($strchangepassword); $PAGE->navbar->add($strchangepassword);
$PAGE->set_title($strchangepassword); $PAGE->set_title($strchangepassword);
$PAGE->set_heading($strchangepassword); $PAGE->set_heading($strchangepassword);
echo $OUTPUT->header(); echo $OUTPUT->header();
if (get_user_preferences('auth_forcepasswordchange')) { if (get_user_preferences('auth_forcepasswordchange')) {
echo $OUTPUT->notification(get_string('forcepasswordchangenotice')); echo $OUTPUT->notification(get_string('forcepasswordchangenotice'));
} }
$mform->display(); $mform->display();
echo $OUTPUT->footer(); echo $OUTPUT->footer();
?> ?>

View file

@ -1,22 +1,24 @@
<?php // $Id$ <?php
require_once("../config.php"); require_once("../config.php");
$data = optional_param('data', '', PARAM_CLEAN); // Formatted as: secret/username $data = optional_param('data', '', PARAM_CLEAN); // Formatted as: secret/username
$p = optional_param('p', '', PARAM_ALPHANUM); // Old parameter: secret $p = optional_param('p', '', PARAM_ALPHANUM); // Old parameter: secret
$s = optional_param('s', '', PARAM_CLEAN); // Old parameter: username $s = optional_param('s', '', PARAM_CLEAN); // Old parameter: username
if (empty($CFG->registerauth)) { $PAGE->set_url(new moodle_url($CFG->wwwroot.'/login/confirm.php'));
if (empty($CFG->registerauth)) {
print_error('cannotusepage2'); print_error('cannotusepage2');
} }
$authplugin = get_auth_plugin($CFG->registerauth); $authplugin = get_auth_plugin($CFG->registerauth);
if (!$authplugin->can_confirm()) { if (!$authplugin->can_confirm()) {
print_error('cannotusepage2'); print_error('cannotusepage2');
} }
if (!empty($data) || (!empty($p) && !empty($s))) { if (!empty($data) || (!empty($p) && !empty($s))) {
if (!empty($data)) { if (!empty($data)) {
$dataelements = explode('/',$data); $dataelements = explode('/',$data);
@ -71,10 +73,10 @@
} else { } else {
print_error('invalidconfirmdata'); print_error('invalidconfirmdata');
} }
} else { } else {
print_error("errorwhenconfirming"); print_error("errorwhenconfirming");
} }
redirect("$CFG->wwwroot/"); redirect("$CFG->wwwroot/");
?> ?>

View file

@ -1,5 +1,5 @@
<?php <?php
// $Id$
// forgot password routine. // forgot password routine.
// find the user and call the appropriate routine for their authentication // find the user and call the appropriate routine for their authentication
// type. // type.
@ -18,6 +18,7 @@ $systemcontext = get_context_instance(CONTEXT_SYSTEM);
$strforgotten = get_string('passwordforgotten'); $strforgotten = get_string('passwordforgotten');
$strlogin = get_string('login'); $strlogin = get_string('login');
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/login/forgot_password.php'));
$PAGE->navbar->add($strlogin, get_login_url()); $PAGE->navbar->add($strlogin, get_login_url());
$PAGE->navbar->add($strforgotten); $PAGE->navbar->add($strforgotten);

View file

@ -1,71 +1,93 @@
<?php // $Id$ <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once("../config.php"); /**
* This file is part of the login section Moodle
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package login
*/
redirect_if_major_upgrade_required(); require_once("../config.php");
$loginguest = optional_param('loginguest', 0, PARAM_BOOL); // determines whether visitors are logged in as guest automatically redirect_if_major_upgrade_required();
$testcookies = optional_param('testcookies', 0, PARAM_BOOL); // request cookie test
$context = get_context_instance(CONTEXT_SYSTEM); $loginguest = optional_param('loginguest', 0, PARAM_BOOL); // determines whether visitors are logged in as guest automatically
$PAGE->set_course($SITE); $testcookies = optional_param('testcookies', 0, PARAM_BOOL); // request cookie test
$context = get_context_instance(CONTEXT_SYSTEM);
$PAGE->set_course($SITE);
/// Initialize variables /// Initialize variables
$errormsg = ''; $errormsg = '';
$errorcode = 0; $errorcode = 0;
/// Check for timed out sessions /// Check for timed out sessions
if (!empty($SESSION->has_timed_out)) { if (!empty($SESSION->has_timed_out)) {
$session_has_timed_out = true; $session_has_timed_out = true;
unset($SESSION->has_timed_out); unset($SESSION->has_timed_out);
} else { } else {
$session_has_timed_out = false; $session_has_timed_out = false;
} }
/// auth plugins may override these - SSO anyone? /// auth plugins may override these - SSO anyone?
$frm = false; $frm = false;
$user = false; $user = false;
$authsequence = get_enabled_auth_plugins(true); // auths, in sequence $authsequence = get_enabled_auth_plugins(true); // auths, in sequence
foreach($authsequence as $authname) { foreach($authsequence as $authname) {
$authplugin = get_auth_plugin($authname); $authplugin = get_auth_plugin($authname);
$authplugin->loginpage_hook(); $authplugin->loginpage_hook();
} }
//HTTPS is potentially required in this page //HTTPS is potentially required in this page
httpsrequired(); httpsrequired();
$PAGE->set_url("$CFG->httpswwwroot/login/index.php"); $PAGE->set_url("$CFG->httpswwwroot/login/index.php");
/// Define variables used in page /// Define variables used in page
if (!$site = get_site()) { if (!$site = get_site()) {
print_error('siteisnotdefined', 'debug'); print_error('siteisnotdefined', 'debug');
} }
if (empty($CFG->langmenu)) { if (empty($CFG->langmenu)) {
$langmenu = ""; $langmenu = "";
} else { } else {
$currlang = current_language(); $currlang = current_language();
$langs = get_list_of_languages(); $langs = get_list_of_languages();
$select = html_select::make_popup_form("$CFG->httpswwwroot/login/index.php", 'lang', $langs, 'chooselang', $currlang); $select = html_select::make_popup_form("$CFG->httpswwwroot/login/index.php", 'lang', $langs, 'chooselang', $currlang);
$select->nothinglabel = false; $select->nothinglabel = false;
$select->set_label(get_accesshide(get_string('language'))); $select->set_label(get_accesshide(get_string('language')));
$langmenu = $OUTPUT->select($select); $langmenu = $OUTPUT->select($select);
} }
$loginsite = get_string("loginsite"); $loginsite = get_string("loginsite");
$PAGE->navbar->add($loginsite); $PAGE->navbar->add($loginsite);
if ($user !== false or $frm !== false) { if ($user !== false or $frm !== false) {
// some auth plugin already supplied these // some auth plugin already supplied these
} else if ((!empty($SESSION->wantsurl) and strstr($SESSION->wantsurl,'username=guest')) or $loginguest) { } else if ((!empty($SESSION->wantsurl) and strstr($SESSION->wantsurl,'username=guest')) or $loginguest) {
/// Log in as guest automatically (idea from Zbigniew Fiedorowicz) /// Log in as guest automatically (idea from Zbigniew Fiedorowicz)
$frm->username = 'guest'; $frm->username = 'guest';
$frm->password = 'guest'; $frm->password = 'guest';
} else if (!empty($SESSION->wantsurl) && file_exists($CFG->dirroot.'/login/weblinkauth.php')) { } else if (!empty($SESSION->wantsurl) && file_exists($CFG->dirroot.'/login/weblinkauth.php')) {
// Handles the case of another Moodle site linking into a page on this site // Handles the case of another Moodle site linking into a page on this site
//TODO: move weblink into own auth plugin //TODO: move weblink into own auth plugin
include($CFG->dirroot.'/login/weblinkauth.php'); include($CFG->dirroot.'/login/weblinkauth.php');
@ -78,18 +100,18 @@
$frm = data_submitted(); $frm = data_submitted();
} }
} else { } else {
$frm = data_submitted(); $frm = data_submitted();
} }
/// Check if the user has actually submitted login data to us /// Check if the user has actually submitted login data to us
if (empty($CFG->usesid) and $testcookies and (get_moodle_cookie() == '')) { // Login without cookie when test requested if (empty($CFG->usesid) and $testcookies and (get_moodle_cookie() == '')) { // Login without cookie when test requested
$errormsg = get_string("cookiesnotenabled"); $errormsg = get_string("cookiesnotenabled");
$errorcode = 1; $errorcode = 1;
} else if ($frm) { // Login WITH cookies } else if ($frm) { // Login WITH cookies
$frm->username = trim(moodle_strtolower($frm->username)); $frm->username = trim(moodle_strtolower($frm->username));
@ -163,7 +185,7 @@
} }
/// Go to my-moodle page instead of homepage if mymoodleredirect enabled /// Go to my-moodle page instead of homepage if mymoodleredirect enabled
if (!has_capability('moodle/site:config', $context) and !empty($CFG->mymoodleredirect) and !isguest()) { if (!has_capability('moodle/site:config', $context) and !empty($CFG->mymoodleredirect) and !has_capability('moodle/legacy:guest',$context, 0, false)) {
if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') { if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
$urltogo = $CFG->wwwroot.'/my/'; $urltogo = $CFG->wwwroot.'/my/';
} }
@ -218,27 +240,27 @@
$errormsg .= get_string('loginlinkmnetuser', 'mnet', "mnet_email.php?u=$frm->username"); $errormsg .= get_string('loginlinkmnetuser', 'mnet', "mnet_email.php?u=$frm->username");
} }
} }
} }
/// Detect problems with timedout sessions /// Detect problems with timedout sessions
if ($session_has_timed_out and !data_submitted()) { if ($session_has_timed_out and !data_submitted()) {
$errormsg = get_string('sessionerroruser', 'error'); $errormsg = get_string('sessionerroruser', 'error');
$errorcode = 4; $errorcode = 4;
} }
/// First, let's remember where the user was trying to get to before they got here /// First, let's remember where the user was trying to get to before they got here
if (empty($SESSION->wantsurl)) { if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = (array_key_exists('HTTP_REFERER',$_SERVER) && $SESSION->wantsurl = (array_key_exists('HTTP_REFERER',$_SERVER) &&
$_SERVER["HTTP_REFERER"] != $CFG->wwwroot && $_SERVER["HTTP_REFERER"] != $CFG->wwwroot &&
$_SERVER["HTTP_REFERER"] != $CFG->wwwroot.'/' && $_SERVER["HTTP_REFERER"] != $CFG->wwwroot.'/' &&
$_SERVER["HTTP_REFERER"] != $CFG->httpswwwroot.'/login/' && $_SERVER["HTTP_REFERER"] != $CFG->httpswwwroot.'/login/' &&
$_SERVER["HTTP_REFERER"] != $CFG->httpswwwroot.'/login/index.php') $_SERVER["HTTP_REFERER"] != $CFG->httpswwwroot.'/login/index.php')
? $_SERVER["HTTP_REFERER"] : NULL; ? $_SERVER["HTTP_REFERER"] : NULL;
} }
/// Redirect to alternative login URL if needed /// Redirect to alternative login URL if needed
if (!empty($CFG->alternateloginurl)) { if (!empty($CFG->alternateloginurl)) {
$loginurl = $CFG->alternateloginurl; $loginurl = $CFG->alternateloginurl;
if (strpos($SESSION->wantsurl, $loginurl) === 0) { if (strpos($SESSION->wantsurl, $loginurl) === 0) {
@ -256,16 +278,16 @@
} }
redirect($loginurl); redirect($loginurl);
} }
/// Generate the login page with forms /// Generate the login page with forms
if (get_moodle_cookie() == '') { if (get_moodle_cookie() == '') {
set_moodle_cookie('nobody'); // To help search for cookies set_moodle_cookie('nobody'); // To help search for cookies
} }
if (empty($frm->username) && $authsequence[0] != 'shibboleth') { // See bug 5184 if (empty($frm->username) && $authsequence[0] != 'shibboleth') { // See bug 5184
if (!empty($_GET["username"])) { if (!empty($_GET["username"])) {
$frm->username = $_GET["username"]; $frm->username = $_GET["username"];
} else { } else {
@ -273,28 +295,25 @@
} }
$frm->password = ""; $frm->password = "";
} }
if (!empty($frm->username)) { if (!empty($frm->username)) {
$focus = "password"; $focus = "password";
} else { } else {
$focus = "username"; $focus = "username";
} }
if (!empty($CFG->registerauth) or is_enabled_auth('none') or !empty($CFG->auth_instructions)) { if (!empty($CFG->registerauth) or is_enabled_auth('none') or !empty($CFG->auth_instructions)) {
$show_instructions = true; $show_instructions = true;
} else { } else {
$show_instructions = false; $show_instructions = false;
} }
$PAGE->set_title("$site->fullname: $loginsite"); $PAGE->set_title("$site->fullname: $loginsite");
$PAGE->set_heading("$site->fullname"); $PAGE->set_heading("$site->fullname");
$PAGE->set_headingmenu("<div class=\"langmenu\">$langmenu</div>"); $PAGE->set_headingmenu("<div class=\"langmenu\">$langmenu</div>");
$PAGE->set_focuscontrol($focus); $PAGE->set_focuscontrol($focus);
echo $OUTPUT->header(); echo $OUTPUT->header();
include("index_form.html"); include("index_form.html");
echo $OUTPUT->footer(); echo $OUTPUT->footer();
?>

View file

@ -1,35 +1,58 @@
<?php // $Id$ <?php
// Logs the user out and sends them to the home page
require_once("../config.php"); // This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// can be overriden by auth plugins /**
$redirect = $CFG->wwwroot.'/'; * Logs the user out and sends them to the home page
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package login
*/
$sesskey = optional_param('sesskey', '__notpresent__', PARAM_RAW); // we want not null default to prevent required sesskey warning require_once("../config.php");
if (!isloggedin()) { // can be overriden by auth plugins
$redirect = $CFG->wwwroot.'/';
$sesskey = optional_param('sesskey', '__notpresent__', PARAM_RAW); // we want not null default to prevent required sesskey warning
if (!isloggedin()) {
// no confirmation, user has already logged out // no confirmation, user has already logged out
require_logout(); require_logout();
redirect($redirect); redirect($redirect);
} else if (!confirm_sesskey($sesskey)) { } else if (!confirm_sesskey($sesskey)) {
$url = new moodle_url($CFG->wwwroot.'/login/logout.php');
if ($sesskey !== '__notpresent__') $url->param('sesskey', $sesskey);
$PAGE->set_url($url);
$PAGE->set_title($SITE->fullname); $PAGE->set_title($SITE->fullname);
$PAGE->set_heading($SITE->fullname); $PAGE->set_heading($SITE->fullname);
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('logoutconfirm'), 'logout.php', $CFG->wwwroot.'/'); echo $OUTPUT->confirm(get_string('logoutconfirm'), 'logout.php', $CFG->wwwroot.'/');
echo $OUTPUT->footer(); echo $OUTPUT->footer();
die; die;
} }
$authsequence = get_enabled_auth_plugins(); // auths, in sequence $authsequence = get_enabled_auth_plugins(); // auths, in sequence
foreach($authsequence as $authname) { foreach($authsequence as $authname) {
$authplugin = get_auth_plugin($authname); $authplugin = get_auth_plugin($authname);
$authplugin->logoutpage_hook(); $authplugin->logoutpage_hook();
} }
require_logout(); require_logout();
redirect($redirect); redirect($redirect);
?>

View file

@ -11,6 +11,8 @@ if (isloggedin() and !isguestuser()) {
redirect( $CFG->wwwroot.'/', get_string('loginalready'), 5); redirect( $CFG->wwwroot.'/', get_string('loginalready'), 5);
} }
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/login/mnet_email.php', array('u'=>$username)));
$PAGE->navbar->add('MNET ID Provider'); $PAGE->navbar->add('MNET ID Provider');
$PAGE->set_title('MNET ID Provider'); $PAGE->set_title('MNET ID Provider');
$PAGE->set_heading('MNET ID Provider'); $PAGE->set_heading('MNET ID Provider');
@ -40,5 +42,3 @@ echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
echo $OUTPUT->footer(); echo $OUTPUT->footer();
?>

View file

@ -1,37 +1,60 @@
<?php // $Id$ <?php
require_once('../config.php'); // This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This file is part of the login section Moodle
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package login
*/
require_once('../config.php');
/**
* Returns whether or not the captcha element is enabled, and the admin settings fulfil its requirements. * Returns whether or not the captcha element is enabled, and the admin settings fulfil its requirements.
* @return bool * @return bool
*/ */
function signup_captcha_enabled() { function signup_captcha_enabled() {
global $CFG; global $CFG;
return !empty($CFG->recaptchapublickey) && !empty($CFG->recaptchaprivatekey) && get_config('auth/email', 'recaptcha'); return !empty($CFG->recaptchapublickey) && !empty($CFG->recaptchaprivatekey) && get_config('auth/email', 'recaptcha');
} }
require_once('signup_form.php'); require_once('signup_form.php');
if (empty($CFG->registerauth)) { if (empty($CFG->registerauth)) {
print_error("Sorry, you may not use this page."); print_error("Sorry, you may not use this page.");
} }
$authplugin = get_auth_plugin($CFG->registerauth); $authplugin = get_auth_plugin($CFG->registerauth);
if (!$authplugin->can_signup()) { if (!$authplugin->can_signup()) {
print_error("Sorry, you may not use this page."); print_error("Sorry, you may not use this page.");
} }
//HTTPS is potentially required in this page //HTTPS is potentially required in this page
httpsrequired(); httpsrequired();
$mform_signup = new login_signup_form(); $mform_signup = new login_signup_form();
if ($mform_signup->is_cancelled()) { if ($mform_signup->is_cancelled()) {
redirect(get_login_url()); redirect(get_login_url());
} else if ($user = $mform_signup->get_data()) { } else if ($user = $mform_signup->get_data()) {
$user->confirmed = 0; $user->confirmed = 0;
$user->lang = current_language(); $user->lang = current_language();
$user->firstaccess = time(); $user->firstaccess = time();
@ -41,31 +64,29 @@
$authplugin->user_signup($user, true); // prints notice and link to login/index.php $authplugin->user_signup($user, true); // prints notice and link to login/index.php
exit; //never reached exit; //never reached
} }
$newaccount = get_string('newaccount'); $newaccount = get_string('newaccount');
$login = get_string('login'); $login = get_string('login');
if (empty($CFG->langmenu)) { if (empty($CFG->langmenu)) {
$langmenu = ''; $langmenu = '';
} else { } else {
$currlang = current_language(); $currlang = current_language();
$langs = get_list_of_languages(); $langs = get_list_of_languages();
$select = html_select::make_popup_form("$CFG->wwwroot/login/signup.php", 'lang', $langs, 'chooselang', $currlang); $select = html_select::make_popup_form("$CFG->wwwroot/login/signup.php", 'lang', $langs, 'chooselang', $currlang);
$select->nothinglabel = false; $select->nothinglabel = false;
$langmenu = $OUTPUT->select($select); $langmenu = $OUTPUT->select($select);
} }
$PAGE->navbar->add($login); $PAGE->navbar->add($login);
$PAGE->navbar->add($newaccount); $PAGE->navbar->add($newaccount);
$PAGE->set_title($newaccount); $PAGE->set_url(new moodle_url($CFG->wwwroot.'/login/signup.php'));
$PAGE->set_heading($newaccount); $PAGE->set_title($newaccount);
$PAGE->set_focuscontrol($mform_signup->focus()); $PAGE->set_heading($newaccount);
$PAGE->set_headingmenu("<div class=\"langmenu\">$langmenu</div>"); $PAGE->set_focuscontrol($mform_signup->focus());
$PAGE->set_headingmenu("<div class=\"langmenu\">$langmenu</div>");
echo $OUTPUT->header(); echo $OUTPUT->header();
$mform_signup->display(); $mform_signup->display();
echo $OUTPUT->footer(); echo $OUTPUT->footer();
?>