Skip to content

Commit

Permalink
MDL-49583 enrol: enrol/index.php page doesn't handle direct access well
Browse files Browse the repository at this point in the history
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()
  • Loading branch information
NeillM committed Apr 29, 2015
1 parent 6979298 commit e4e261b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions enrol/index.php
Expand Up @@ -28,6 +28,12 @@
$id = required_param('id', PARAM_INT);

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());
Expand Down

0 comments on commit e4e261b

Please sign in to comment.