Moving to GitHub.
[platal.git] / classes / xorgsession.php
index 73bdb9f..2a9e73d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2011 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -138,14 +138,19 @@ class XorgSession extends PlSession
 
         $user = User::getSilent($login);
 
-        if (!is_null($user) && S::suid()) {
-            $success = (S::suid('uid') == $user->id());
+        if (is_null($user)) {
+            Platal::page()->trigError(self::TEXT_INVALID_LOGIN);
+            $success = false;
         } else {
-            $success = $this->checkPassword($login, $user, Post::v('response'));
+            if (S::suid()) {
+                $success = (S::suid('uid') == $user->id());
+            } else {
+                $success = $this->checkPassword($login, $user, Post::v('response'));
+            }
         }
 
         if ($success) {
-            S::set('auth', AUTH_MDP);
+            S::set('auth', AUTH_PASSWD);
             S::kill('challenge');
             S::logger($user->id())->log('auth_ok');
         }
@@ -161,7 +166,7 @@ class XorgSession extends PlSession
             return true;
         }
         if ($level == AUTH_SUID) {
-            S::set('auth', AUTH_MDP);
+            S::set('auth', AUTH_PASSWD);
         }
 
         // Loads uid and hruid into the session for developement conveniance.
@@ -178,6 +183,13 @@ class XorgSession extends PlSession
                 $this->setAccessCookie(false, S::i('auth_by_cookie') != $user->id());
             } else {
                 $this->killAccessCookie();
+
+                // If login for an external website and not activating cookie,
+                // mark that we want to disconnect once external auth checks
+                // have been performed.
+                if (Post::b('external_auth')) {
+                    S::set('external_auth_exit', true);
+                }
             }
         }
 
@@ -301,7 +313,7 @@ class XorgSession extends PlSession
 
     public function sureLevel()
     {
-        return AUTH_MDP;
+        return AUTH_PASSWD;
     }
 
 
@@ -336,5 +348,5 @@ class XorgSession extends PlSession
     }
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>