diff --git a/user/profile.php b/user/profile.php index f0f7c26364a..fced2e9a683 100644 --- a/user/profile.php +++ b/user/profile.php @@ -48,8 +48,6 @@ $PAGE->set_url('/user/profile.php', array('id' => $userid)); if (!empty($CFG->forceloginforprofiles)) { require_login(); if (isguestuser()) { - $SESSION->wantsurl = $PAGE->url->out(false); - $PAGE->set_context(context_system::instance()); echo $OUTPUT->header(); echo $OUTPUT->confirm(get_string('guestcantaccessprofiles', 'error'), diff --git a/user/view.php b/user/view.php index 0a0b6b7215f..25fe1cc843c 100644 --- a/user/view.php +++ b/user/view.php @@ -52,23 +52,28 @@ $systemcontext = context_system::instance(); $coursecontext = context_course::instance($course->id); $usercontext = context_user::instance($user->id, IGNORE_MISSING); -// Require login first. +// Check we are not trying to view guest's profile. if (isguestuser($user)) { // Can not view profile of guest - thre is nothing to see there. print_error('invaliduserid'); } +$PAGE->set_context($coursecontext); + if (!empty($CFG->forceloginforprofiles)) { require_login(); // We can not log in to course due to the parent hack below. // Guests do not have permissions to view anyone's profile if forceloginforprofiles is set. if (isguestuser()) { - $SESSION->wantsurl = $PAGE->url->out(false); - redirect(get_login_url()); + echo $OUTPUT->header(); + echo $OUTPUT->confirm(get_string('guestcantaccessprofiles', 'error'), + get_login_url(), + $CFG->wwwroot); + echo $OUTPUT->footer(); + die; } } -$PAGE->set_context($coursecontext); $PAGE->set_course($course); $PAGE->set_pagetype('course-view-' . $course->format); // To get the blocks exactly like the course. $PAGE->add_body_class('path-user'); // So we can style it independently.