MDL-49583 enrol: enrol/index.php page doesn't handle direct access well

Before this patch if a user who is not logged in to Moodle accesses the
enrol/index.php page directly they were redirected to the Moodle front
page after login, rather than back to a page that would allow them to
self enrol, if it is enabled on the course.

This change will cause a user who directly accesses the page to be
redirected back to it after they have logged in, unless the course has guest
access enabled.

Thanks to Marina Glancy for suggesting the use of get_referer()
This commit is contained in:
Neill Magill 2015-03-19 11:32:33 +00:00
parent 84ea226616
commit ccd3dd5bc9

View File

@ -29,6 +29,12 @@ $id = required_param('id', PARAM_INT);
$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
if (!isloggedin()) {
$referer = clean_param(get_referer(), PARAM_LOCALURL);
if (empty($referer)) {
// A user that is not logged in has arrived directly on this page,
// they should be redirected to the course page they are trying to enrol on after logging in.
$SESSION->wantsurl = "$CFG->wwwroot/course/view.php?id=$id";
}
// do not use require_login here because we are usually coming from it,
// it would also mess up the SESSION->wantsurl
redirect(get_login_url());