autologinguest disruptive behavior on non-guest-enabled pages (m2.9)

autologinguest disruptive behavior on non-guest-enabled pages (m2.9)

by Dave Perry -
Number of replies: 1
Picture of Testers

Since we enabled autologinguest (for some pages which are hosting content as part of an externally-funded project) we have had users get confused by the fact that, if you aren't logged in and try to click a link to a page which does NOT have guest access enabled, it doesn't even offer you the login form.

There is no 'logout' link from guest mode either, so we hacked one in ourselves - so now when in as guest, the Login link is logout as guest.

But still, pages which call require_login() and don't have the guest role enabled should be offering the login form. I am deeming this an issue as we have had lots of calls from people who have been stuck in this. And telling people to close of their browser session completely including all open windows is not always a helpful or convenient answer for the end user.

I have a tried a quick hack yesterday (not having any written plugins in strict moodle code I don't understand the db get_record etc stuff) in lib/moodlelib.php (starting at line 2450):

 function course_has_guest_enabled($course_id) {
  //$db = mysql_connect("localhost","root","admin"); $db = mysql_select_db("moodle29",$db);
  $sql = "SELECT status FROM mdl_enrol WHERE courseid=" . $course_id . " AND enrol='guest'";
  $query = mysql_query($sql);
  $row = mysql_fetch_object($query);
  if($row->status == 0) { return 1; } else { return 0; }
 }

add at 2515:

   //HCUK - it's a course, set our own flag
   $loading_course = true;
   $loading_course_id = $courseorid;

then at 2564:

        if ($autologinguest && $loading_course_id > 0 && course_has_guest_access($loading_course_id) == 0) {
   //stop moodle trying to autologin as guest to a page that doesn't have guest access enabled
   $SESSION->wantsurl = qualified_me();
   redirect(get_login_url());   
  }

But that broke autologin as guest. Suggestions welcome - I have logged this as a bug on the tracker, but have basically been told that unless enough people agree with me no changes will be made.

Average of ratings: -
In reply to Dave Perry

Re: autologinguest disruptive behavior on non-guest-enabled pages (m2.9)

by Allida Branton -

I just figured out how to use the guest log in.  But we need to have guests be able to log out.  Do I need to go to the tracker and vote for this?  Seems necessary to me, you login, you log out.  During testing this process I closed the browser and then opened it and I was still logged in as a guest.  That is not what I want for my site.

I am using 2.6.