MDL-7903 Guests can not enter course that allows guests with key; merged from MOODLE_17_STABLE

This commit is contained in:
skodak 2006-12-18 19:21:10 +00:00
parent 3246ed335d
commit 658e87e302
4 changed files with 12 additions and 11 deletions

View File

@ -8,12 +8,15 @@
require_once("$CFG->dirroot/enrol/enrol.class.php");
$id = required_param('id', PARAM_INT);
$loginasguest = optional_param('loginasguest', 0, PARAM_BOOL);
$loginasguest = optional_param('loginasguest', 0, PARAM_BOOL); // hmm, is this still needed?
require_login();
if ($USER->username == 'guest') { // Guests can't enrol in anything!
redirect($CFG->wwwroot.'/login/index.php');
if (!isloggedin()) {
$wwwroot = $CFG->wwwroot;
if (!empty($CFG->loginhttps)) {
$wwwroot = str_replace('http:','https:', $wwwroot);
}
// do not use require_login here because we are usually comming from it
redirect($wwwroot.'/login/index.php');
}
if (! $course = get_record('course', 'id', $id) ) {
@ -34,7 +37,7 @@
/// thus got to this script by mistake. This might occur if enrolments
/// changed during this session or something
if (has_capability('moodle/course:view', $context) and !has_capability('moodle/legacy:guest', $context)) {
if (has_capability('moodle/course:view', $context) and !has_capability('moodle/legacy:guest', $context, NULL, false)) {
if ($SESSION->wantsurl) {
$destination = $SESSION->wantsurl;
unset($SESSION->wantsurl);

View File

@ -64,7 +64,7 @@ class enrolment_plugin_authorize
}
print_simple_box_start('center', '80%');
if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), $USER->id, false)) {
if ($USER->username == 'guest') { // only real guest user, not for users with guest role
$curcost = get_course_cost($course);
echo '<div align="center">';
echo '<p>'.get_string('paymentrequired').'</p>';

View File

@ -137,11 +137,9 @@ function check_entry($form, $course) {
$groupid = $this->check_group_entry($course->id, $form->password);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if (($form->password == $course->password) or ($groupid !== false) ) {
if (has_capability('moodle/legacy:guest', $context, $USER->id, false)) {
if ($USER->username == 'guest') { // only real user guest, do not use this for users with guest role
$USER->enrolkey[$course->id] = true;
add_to_log($course->id, 'course', 'guest', 'view.php?id='.$course->id, getremoteaddr());

View File

@ -42,7 +42,7 @@ function print_entry($course) {
print_simple_box_start("center");
if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM, SITEID), NULL, false)) {
if ($USER->username == 'guest') { // force login only for guest user, not real users with guest role
if (empty($CFG->loginhttps)) {
$wwwroot = $CFG->wwwroot;
} else {