]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-7903 Guests can not enter course that allows guests with key; merged from MOODLE_...
authorskodak <skodak>
Mon, 18 Dec 2006 19:21:10 +0000 (19:21 +0000)
committerskodak <skodak>
Mon, 18 Dec 2006 19:21:10 +0000 (19:21 +0000)
course/enrol.php
enrol/authorize/enrol.php
enrol/manual/enrol.php
enrol/paypal/enrol.php

index 0b86684c5d6e350a8d71bc2f0bf615908d11a7b3..61419cccf24dc2cc7cbcfd2f7546a66e446d50f6 100644 (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);
index c32e22c9e32f3954f5046b809756394f7e2592f3..a5a60c9b4adc248e650d7961f464d0cacedaa730 100755 (executable)
@@ -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>';
index 0f53667127fb372763a4d6d25d30ec8265df26ca..7bbe82fc4ad0d312e050fe0a0d75503c8146657b 100644 (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());
 
index 5ea01b01b02ace191814ab2a47f1c307e0e6deff..e571851a1ddc418d337d9672a3c58addc0d839a2 100644 (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 {