Skip to content

Commit

Permalink
MDL-17772 fixed guest access; MDL-17754 $USER object initialisation c…
Browse files Browse the repository at this point in the history
…leanup
  • Loading branch information
skodak committed Jan 2, 2009
1 parent b7b64ff commit 1b813f5
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion admin/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@


/// emulate normal session
$USER = get_admin(); /// Temporarily, to provide environment for this script
session_set_user(get_admin()); /// Temporarily, to provide environment for this script

/// ignore admins timezone, language and locale - use site deafult instead!
$USER->timezone = $CFG->timezone;
Expand Down
4 changes: 2 additions & 2 deletions auth/mnet/land.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
$localuser = $mnetauth->confirm_mnet_session($token, $remotewwwroot);

// log in
$USER = get_complete_user_data('id', $localuser->id, $localuser->mnethostid);
complete_user_login($USER);
$user = get_complete_user_data('id', $localuser->id, $localuser->mnethostid);
complete_user_login($user);

if (!empty($localuser->mnet_foreign_host_array)) {
$USER->mnet_foreign_host_array = $localuser->mnet_foreign_host_array;
Expand Down
2 changes: 1 addition & 1 deletion backup/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ function import_backup_file_silently($pathtofile,$destinationcourse,$emptyfirst=
global $CFG,$SESSION,$USER, $DB; // is there such a thing on cron? I guess so..
global $restore; // ick
if (empty($USER)) {
$USER = get_admin();
session_set_user(get_admin());
$USER->admin = 1; // not sure why, but this doesn't get set
}

Expand Down
6 changes: 3 additions & 3 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1414,9 +1414,9 @@ function create_admin_user($user_input=NULL) {

// Log the user in.
set_config('rolesactive', 1);
$USER = get_complete_user_data('username', 'admin');
$USER->newadminuser = 1;
load_all_capabilities();
$user = get_complete_user_data('username', 'admin');
$user->newadminuser = 1;
complete_user_login($user);

if (!defined('CLI_UPGRADE')||!CLI_UPGRADE) {
redirect("$CFG->wwwroot/user/editadvanced.php?id=$user->id"); // Edit thyself
Expand Down
2 changes: 1 addition & 1 deletion lib/sessionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function check_user_initialised() {
$user = guest_user();
}
}
if (!$user and !empty($_SERVER['HTTP_REFERER'])) {
if (!empty($CFG->guestloginbutton) and !$user and !empty($_SERVER['HTTP_REFERER'])) {
// automaticaly log in users coming from search engine results
if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false ) {
$user = guest_user();
Expand Down
19 changes: 11 additions & 8 deletions lib/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,17 @@ function stripslashes_deep($value) {
// set default locale and themes - might be changed again later from require_login()
course_setup();

if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation
if (isset($_SERVER['HTTP_USER_AGENT']) and empty($USER->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest)
if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
(strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false )) {
if ($USER = get_complete_user_data("username", "w3cvalidator")) {
$USER->ignoresesskey = true;
} else {
$USER = guest_user();
if (!empty($CFG->guestloginbutton)) {
if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation
if (isset($_SERVER['HTTP_USER_AGENT']) and empty($USER->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest)
if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
(strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false )) {
if ($user = get_complete_user_data("username", "w3cvalidator")) {
$user->ignoresesskey = true;
} else {
$user = guest_user();
}
session_set_user($user);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions login/confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@

// The user has confirmed successfully, let's log them in

if (!$USER = get_complete_user_data('username', $username)) {
if (!$user = get_complete_user_data('username', $username)) {
print_error('cannotfinduser', '', '', $username);
}

set_moodle_cookie($USER->username);
complete_user_login($user);

if ( ! empty($SESSION->wantsurl) ) { // Send them where they were going
$goto = $SESSION->wantsurl;
Expand Down
4 changes: 1 addition & 3 deletions rss/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@

$lifetime = 3600; // Seconds for files to remain in caches - 1 hour

// hack for problems with concurrent use of NO_MOODLE_COOKIES and capabilities MDL-7243
// this is a big one big hack - NO_MOODLE_COOKIES is not compatible with capabilities MDL-7243
// it should be replaced once we get to codes in urls
$USER = new object();
$USER->id = 0;

// disable moodle specific debug messages
disable_debugging();
Expand Down

0 comments on commit 1b813f5

Please sign in to comment.