MDL-23747 fixed multiple PAGE->context issues, improved coding style and added license headers

This commit is contained in:
Petr Skoda 2010-08-11 08:04:57 +00:00
parent e2a8447777
commit c30949a93a
11 changed files with 233 additions and 99 deletions

View File

@ -16,14 +16,15 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This file is part of the login section Moodle * Change password page.
* *
* @copyright 1999 Martin Dougiamas http://dougiamas.com * @package core
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @subpackage auth
* @package login * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once('../config.php'); require('../config.php');
require_once('change_password_form.php'); require_once('change_password_form.php');
$id = optional_param('id', SITEID, PARAM_INT); // current course $id = optional_param('id', SITEID, PARAM_INT); // current course
@ -33,6 +34,7 @@ if ($id !== SITEID) {
$url->param('id', $id); $url->param('id', $id);
} }
$PAGE->set_url($url); $PAGE->set_url($url);
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$strparticipants = get_string('participants'); $strparticipants = get_string('participants');

View File

@ -1,8 +1,30 @@
<?php <?php
if (!defined('MOODLE_INTERNAL')) { // This file is part of Moodle - http://moodle.org/
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page //
} // 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/>.
/**
* Change password form definition.
*
* @package core
* @subpackage auth
* @copyright 2006 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once $CFG->libdir.'/formslib.php'; require_once $CFG->libdir.'/formslib.php';
@ -11,7 +33,7 @@ class login_change_password_form extends moodleform {
function definition() { function definition() {
global $USER, $CFG; global $USER, $CFG;
$mform =& $this->_form; $mform = $this->_form;
$mform->addElement('header', '', get_string('changepassword'), ''); $mform->addElement('header', '', get_string('changepassword'), '');

View File

@ -1,6 +1,30 @@
<?php <?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/>.
/**
* Confirm self registered user.
*
* @package core
* @subpackage auth
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../config.php');
$data = optional_param('data', '', PARAM_CLEAN); // Formatted as: secret/username $data = optional_param('data', '', PARAM_CLEAN); // Formatted as: secret/username
@ -8,6 +32,7 @@ $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
$PAGE->set_url('/login/confirm.php'); $PAGE->set_url('/login/confirm.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
if (empty($CFG->registerauth)) { if (empty($CFG->registerauth)) {
print_error('cannotusepage2'); print_error('cannotusepage2');

View File

@ -1,28 +1,27 @@
<?php <?php
/////////////////////////////////////////////////////////////////////////// // This file is part of Moodle - http://moodle.org/
// // //
// This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify
// Moodle - Modular Object-Oriented Dynamic Learning Environment // // it under the terms of the GNU General Public License as published by
// // // the Free Software Foundation, either version 3 of the License, or
// Moodle is free software: you can redistribute it and/or modify // // (at your option) any later version.
// it under the terms of the GNU General Public License as published by // //
// the Free Software Foundation, either version 3 of the License, or // // Moodle is distributed in the hope that it will be useful,
// (at your option) any later version. // // but WITHOUT ANY WARRANTY; without even the implied warranty of
// // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Moodle is distributed in the hope that it will be useful, // // GNU General Public License for more details.
// but WITHOUT ANY WARRANTY; without even the implied warranty of // //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // You should have received a copy of the GNU General Public License
// GNU General Public License for more details. // // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// //
// You should have received a copy of the GNU General Public License //
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
// //
///////////////////////////////////////////////////////////////////////////
/**
/*
* This script can set environment variables in the current session * This script can set environment variables in the current session
*
* @package core
* @subpackage auth
* @copyright 2009 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require('../config.php'); require('../config.php');

View File

@ -1,10 +1,32 @@
<?php <?php
// forgot password routine. // This file is part of Moodle - http://moodle.org/
// find the user and call the appropriate routine for their authentication //
// type. // 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'); /**
* Forgot password routine.
*
* Finds the user and calls the appropriate routine for their authentication type.
*
* @package core
* @subpackage auth
* @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../config.php');
require_once('forgot_password_form.php'); require_once('forgot_password_form.php');
$p_secret = optional_param('p', false, PARAM_RAW); $p_secret = optional_param('p', false, PARAM_RAW);
@ -13,14 +35,17 @@ $p_username = optional_param('s', false, PARAM_RAW);
httpsrequired(); httpsrequired();
$systemcontext = get_context_instance(CONTEXT_SYSTEM); $systemcontext = get_context_instance(CONTEXT_SYSTEM);
$PAGE->set_url('/login/forgot_password.php');
$PAGE->set_context($syscontext);
// setup text strings // setup text strings
$strforgotten = get_string('passwordforgotten'); $strforgotten = get_string('passwordforgotten');
$strlogin = get_string('login'); $strlogin = get_string('login');
$PAGE->set_url('/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);
$PAGE->set_title($strforgotten);
$PAGE->set_heading($COURSE->fullname);
// if alternatepasswordurl is defined, then we'll just head there // if alternatepasswordurl is defined, then we'll just head there
if (!empty($CFG->forgottenpasswordurl)) { if (!empty($CFG->forgottenpasswordurl)) {
@ -39,9 +64,6 @@ if ($p_secret !== false) {
update_login_count(); update_login_count();
$PAGE->set_title($strforgotten);
$PAGE->set_heading($COURSE->fullname);
$user = get_complete_user_data('username', $p_username); $user = get_complete_user_data('username', $p_username);
if (!empty($user) and $user->secret === '') { if (!empty($user) and $user->secret === '') {
echo $OUTPUT->header(); echo $OUTPUT->header();
@ -132,8 +154,6 @@ if ($mform->is_cancelled()) {
} }
} }
$PAGE->set_title($strforgotten);
$PAGE->set_heading($COURSE->fullname);
echo $OUTPUT->header(); echo $OUTPUT->header();
if (empty($user->email) or !empty($CFG->protectusernames)) { if (empty($user->email) or !empty($CFG->protectusernames)) {
@ -152,8 +172,6 @@ if ($mform->is_cancelled()) {
/// DISPLAY FORM /// DISPLAY FORM
$PAGE->set_title($strforgotten);
$PAGE->set_heading($COURSE->fullname);
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->box(get_string('passwordforgotteninstructions2'), 'generalbox boxwidthnormal boxaligncenter'); echo $OUTPUT->box(get_string('passwordforgotteninstructions2'), 'generalbox boxwidthnormal boxaligncenter');

View File

@ -1,16 +1,37 @@
<?php <?php
if (!defined('MOODLE_INTERNAL')) { // This file is part of Moodle - http://moodle.org/
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page //
} // 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/>.
/**
* Reset forgotten password form definition.
*
* @package core
* @subpackage auth
* @copyright 2006 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once $CFG->libdir.'/formslib.php'; require_once $CFG->libdir.'/formslib.php';
class login_forgot_password_form extends moodleform { class login_forgot_password_form extends moodleform {
function definition() { function definition() {
$mform =& $this->_form; $mform = $this->_form;
$renderer =& $mform->defaultRenderer();
$mform->addElement('header', '', get_string('searchbyusername'), ''); $mform->addElement('header', '', get_string('searchbyusername'), '');

View File

@ -16,22 +16,27 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This file is part of the login section Moodle * Main login page.
* *
* @copyright 1999 Martin Dougiamas http://dougiamas.com * @package core
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @subpackage auth
* @package login * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once("../config.php"); require('../config.php');
redirect_if_major_upgrade_required(); redirect_if_major_upgrade_required();
$loginguest = optional_param('loginguest', 0, PARAM_BOOL); // determines whether visitors are logged in as guest automatically $loginguest = optional_param('loginguest', 0, PARAM_BOOL); // determines whether visitors are logged in as guest automatically
$testcookies = optional_param('testcookies', 0, PARAM_BOOL); // request cookie test $testcookies = optional_param('testcookies', 0, PARAM_BOOL); // request cookie test
//HTTPS is potentially required in this page
httpsrequired();
$context = get_context_instance(CONTEXT_SYSTEM); $context = get_context_instance(CONTEXT_SYSTEM);
$PAGE->set_course($SITE); $PAGE->set_url("$CFG->httpswwwroot/login/index.php");
$PAGE->set_context($context);
$PAGE->set_pagelayout('login'); $PAGE->set_pagelayout('login');
/// Initialize variables /// Initialize variables
@ -56,11 +61,6 @@ foreach($authsequence as $authname) {
$authplugin->loginpage_hook(); $authplugin->loginpage_hook();
} }
//HTTPS is potentially required in this page
httpsrequired();
$PAGE->set_url("$CFG->httpswwwroot/login/index.php");
/// Define variables used in page /// Define variables used in page
$site = get_site(); $site = get_site();

View File

@ -18,14 +18,18 @@
/** /**
* Logs the user out and sends them to the home page * Logs the user out and sends them to the home page
* *
* @copyright 1999 Martin Dougiamas http://dougiamas.com * @package core
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @subpackage auth
* @package login * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once("../config.php"); require_once('../config.php');
// can be overriden by auth plugins $PAGE->set_url('/login/logout.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
// can be overridden by auth plugins
$redirect = $CFG->wwwroot.'/'; $redirect = $CFG->wwwroot.'/';
$sesskey = optional_param('sesskey', '__notpresent__', PARAM_RAW); // we want not null default to prevent required sesskey warning $sesskey = optional_param('sesskey', '__notpresent__', PARAM_RAW); // we want not null default to prevent required sesskey warning
@ -36,13 +40,10 @@ if (!isloggedin()) {
redirect($redirect); redirect($redirect);
} else if (!confirm_sesskey($sesskey)) { } else if (!confirm_sesskey($sesskey)) {
$url = new moodle_url('/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'), new moodle_url($PAGE->url, array('sesskey'=>sesskey())), $CFG->wwwroot.'/');
echo $OUTPUT->footer(); echo $OUTPUT->footer();
die; die;
} }

View File

@ -1,5 +1,29 @@
<?php <?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/>.
/**
* Magic that deals restored users without passwords.
*
* @package core
* @subpackage auth
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// This is one "supplanter" form that generates // This is one "supplanter" form that generates
// one correct forgot_password.php request in // one correct forgot_password.php request in
// order to get the mailout for 'restored' users // order to get the mailout for 'restored' users
@ -11,16 +35,14 @@
// part of each plugin, but now now. See MDL-20846 // part of each plugin, but now now. See MDL-20846
// for the rationale for this implementation. // for the rationale for this implementation.
if (!defined('MOODLE_INTERNAL')) { defined('MOODLE_INTERNAL') || die();
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
require_once $CFG->libdir.'/formslib.php'; require_once $CFG->libdir.'/formslib.php';
class login_forgot_password_form extends moodleform { class login_forgot_password_form extends moodleform {
function definition() { function definition() {
$mform =& $this->_form; $mform = $this->_form;
$username = $this->_customdata['username']; $username = $this->_customdata['username'];

View File

@ -16,39 +16,32 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This file is part of the login section Moodle * user signup page.
* *
* @copyright 1999 Martin Dougiamas http://dougiamas.com * @package core
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @subpackage auth
* @package login * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once('../config.php'); require('../config.php');
/**
* Returns whether or not the captcha element is enabled, and the admin settings fulfil its requirements.
* @return bool
*/
function signup_captcha_enabled() {
global $CFG;
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('notlocalisederrormessage', '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('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
} }
//HTTPS is potentially required in this page //HTTPS is potentially required in this page
httpsrequired(); httpsrequired();
$PAGE->set_url('/login/signup.php'); $PAGE->set_url('/login/signup.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$mform_signup = new login_signup_form(); $mform_signup = new login_signup_form();
if ($mform_signup->is_cancelled()) { if ($mform_signup->is_cancelled()) {
@ -62,8 +55,8 @@ if ($mform_signup->is_cancelled()) {
$user->mnethostid = $CFG->mnet_localhost_id; $user->mnethostid = $CFG->mnet_localhost_id;
$user->secret = random_string(15); $user->secret = random_string(15);
$user->auth = $CFG->registerauth; $user->auth = $CFG->registerauth;
$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
} }

View File

@ -1,8 +1,30 @@
<?php <?php
if (!defined('MOODLE_INTERNAL')) { // This file is part of Moodle - http://moodle.org/
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page //
} // 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/>.
/**
* User sign-up form.
*
* @package core
* @subpackage auth
* @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
require_once($CFG->dirroot.'/user/profile/lib.php'); require_once($CFG->dirroot.'/user/profile/lib.php');
@ -11,7 +33,7 @@ class login_signup_form extends moodleform {
function definition() { function definition() {
global $USER, $CFG; global $USER, $CFG;
$mform =& $this->_form; $mform = $this->_form;
$mform->addElement('header', '', get_string('createuserandpass'), ''); $mform->addElement('header', '', get_string('createuserandpass'), '');
@ -70,7 +92,7 @@ class login_signup_form extends moodleform {
$mform->setDefault('country', ''); $mform->setDefault('country', '');
} }
if (signup_captcha_enabled()) { if ($this->signup_captcha_enabled()) {
$mform->addElement('recaptcha', 'recaptcha_element', get_string('recaptcha', 'auth'), array('https' => $CFG->loginhttps)); $mform->addElement('recaptcha', 'recaptcha_element', get_string('recaptcha', 'auth'), array('https' => $CFG->loginhttps));
$mform->addHelpButton('recaptcha_element', 'recaptcha', 'auth'); $mform->addHelpButton('recaptcha_element', 'recaptcha', 'auth');
} }
@ -90,7 +112,7 @@ class login_signup_form extends moodleform {
} }
function definition_after_data(){ function definition_after_data(){
$mform =& $this->_form; $mform = $this->_form;
$mform->applyFilter('username', 'trim'); $mform->applyFilter('username', 'trim');
} }
@ -145,7 +167,7 @@ class login_signup_form extends moodleform {
$errors['password'] = $errmsg; $errors['password'] = $errmsg;
} }
if (signup_captcha_enabled()) { if ($this->signup_captcha_enabled()) {
$recaptcha_element = $this->_form->getElement('recaptcha_element'); $recaptcha_element = $this->_form->getElement('recaptcha_element');
if (!empty($this->_form->_submitValues['recaptcha_challenge_field'])) { if (!empty($this->_form->_submitValues['recaptcha_challenge_field'])) {
$challenge_field = $this->_form->_submitValues['recaptcha_challenge_field']; $challenge_field = $this->_form->_submitValues['recaptcha_challenge_field'];
@ -160,6 +182,15 @@ class login_signup_form extends moodleform {
return $errors; return $errors;
} }
/**
* Returns whether or not the captcha element is enabled, and the admin settings fulfil its requirements.
* @return bool
*/
function signup_captcha_enabled() {
global $CFG;
return !empty($CFG->recaptchapublickey) && !empty($CFG->recaptchaprivatekey) && get_config('auth/email', 'recaptcha');
}
} }