]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9399 auth/ldap: ntlmsso_finish() now completes the user session setup
authormartinlanghoff <martinlanghoff>
Wed, 14 Nov 2007 22:09:45 +0000 (22:09 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 14 Nov 2007 22:09:45 +0000 (22:09 +0000)
As IƱaki points out, ntlmsso_finish() needs to do all the setup that
login/index.php would do for a user once auth succeeds. With this
patch, the session setup is complete so the logon is usable.

auth/ldap/auth.php

index 2d4b8c8b84fa05d22ec1ad345f00f813db7910d2..147c864dabe97f2dc2cf7821282ddc696037b943 100644 (file)
@@ -1796,7 +1796,7 @@ class auth_plugin_ldap extends auth_plugin_base {
      *
      */
     function ntlmsso_finish() {
-        global $CFG;
+        global $CFG, $USER;
 
         $key      = $_SERVER['REMOTE_ADDR']; // add sesskey?
         if ($cookie   = get_config('auth/ldap/ntlmsess', $key)) {
@@ -1809,7 +1809,26 @@ class auth_plugin_ldap extends auth_plugin_base {
                     && $sesskey === sesskey()) {
                     // Here we want to trigger the whole authentication machinery
                     // to make sure no step is bypassed...
-                    authenticate_user_login($username, $sesskey);
+                    $user = authenticate_user_login($username, $sesskey);
+                    if ($user) {
+                        add_to_log(SITEID, 'user', 'login', "view.php?id=$USER->id&course=".SITEID,
+                                   $user->id, 0, $user->id);
+                        $USER = complete_user_login($user);
+
+                        /// Redirection
+                        if (user_not_fully_set_up($USER)) {
+                            $urltogo = $CFG->wwwroot.'/user/edit.php';
+                            // We don't delete $SESSION->wantsurl yet, so we get there later
+                        } else if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0)) {
+                            $urltogo = $SESSION->wantsurl;    /// Because it's an address in this site
+                            unset($SESSION->wantsurl);
+                        } else {
+                            // no wantsurl stored or external - go to homepage
+                            $urltogo = $CFG->wwwroot.'/';
+                            unset($SESSION->wantsurl);
+                        }
+                        redirect($urltogo);
+                    }
                 }
             }
         }