]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17767 yet more loginas refactoring
authorskodak <skodak>
Fri, 2 Jan 2009 15:29:20 +0000 (15:29 +0000)
committerskodak <skodak>
Fri, 2 Jan 2009 15:29:20 +0000 (15:29 +0000)
lib/sessionlib.php

index ed73ef086b78ffad2644c28b0652a7ac1907ae34..299226ecf1e5f00a0e76f61fcde52a8817a4ea0c 100644 (file)
@@ -258,9 +258,7 @@ function get_moodle_cookie() {
  * @return bool
  */
 function is_loggedinas() {
-    global $USER;
-
-    return !empty($USER->realuser);
+    return !empty($_SESSION['USER']->realuser);
 }
 
 /**
@@ -282,23 +280,22 @@ function get_real_user() {
  * @return void
  */
 function session_loginas($userid, $context) {
-    global $USER, $SESSION;
-
     if (is_loggedinas()) {
         return;
     }
 
-    // switch to fresh session
-    $_SESSION['REALSESSION'] = $SESSION;
+    // switch to fresh new $SESSION
+    $_SESSION['REALSESSION'] = $_SESSION['SESSION'];
     $_SESSION['SESSION']     = new object();
 
-/// Create the new USER object with all details and reload needed capabilitites
-    $_SESSION['REALUSER'] = $USER;
-    $USER = get_complete_user_data('id', $userid);
-    $USER->realuser       = $_SESSION['REALUSER']->id;
-    $USER->loginascontext = $context;
-    check_enrolment_plugins($USER);
-    load_all_capabilities();   // reload capabilities
+    /// Create the new $USER object with all details and reload needed capabilitites
+    $_SESSION['REALUSER'] = $_SESSION['USER'];
+    $_SESSION['USER'] = get_complete_user_data('id', $userid);
+    $_SESSION['USER']->realuser       = $_SESSION['REALUSER']->id;
+    $_SESSION['USER']->loginascontext = $context;
+
+    check_enrolment_plugins($_SESSION['USER']);
+    load_all_capabilities();
 }
 
 /**
@@ -306,8 +303,6 @@ function session_loginas($userid, $context) {
  * @return void
  */
 function session_unloginas() {
-    global $USER, $SESSION;
-
     if (!is_loggedinas()) {
         return;
     }