From: skodak Date: Fri, 2 Jan 2009 21:05:16 +0000 (+0000) Subject: MDL-17772 fixed guest access; MDL-17754 $USER object initialisation cleanup X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1b813f5c2a54ea6d69f05da1eabffd7e5e11b5da;p=moodle.git MDL-17772 fixed guest access; MDL-17754 $USER object initialisation cleanup --- diff --git a/admin/cron.php b/admin/cron.php index 0b81230446..5382de471d 100644 --- a/admin/cron.php +++ b/admin/cron.php @@ -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; diff --git a/auth/mnet/land.php b/auth/mnet/land.php index 5008a2fa6f..4dec821c89 100644 --- a/auth/mnet/land.php +++ b/auth/mnet/land.php @@ -33,8 +33,8 @@ $mnetauth = get_auth_plugin('mnet'); $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; diff --git a/backup/lib.php b/backup/lib.php index f8cc143570..14772eff4f 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -615,7 +615,7 @@ 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 } diff --git a/lib/adminlib.php b/lib/adminlib.php index 8ac5a23974..f62b0dac72 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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 diff --git a/lib/sessionlib.php b/lib/sessionlib.php index fe0c4488bc..774e54d063 100644 --- a/lib/sessionlib.php +++ b/lib/sessionlib.php @@ -75,7 +75,7 @@ class moodle_session { $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(); diff --git a/lib/setup.php b/lib/setup.php index 672b9e766f..bf9e4ff335 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -450,14 +450,17 @@ global $HTTPSPAGEREQUIRED; // 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); } } } diff --git a/login/confirm.php b/login/confirm.php index 5e4a15e9a3..72f26f664a 100644 --- a/login/confirm.php +++ b/login/confirm.php @@ -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; diff --git a/rss/file.php b/rss/file.php index 362a350505..d35bff474f 100644 --- a/rss/file.php +++ b/rss/file.php @@ -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();