Merge remote branch 'origin/platal-1.0.0'
[platal.git] / classes / xorgsession.php
index 5c0a3dc..02e34e4 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -52,7 +52,7 @@ class XorgSession extends PlSession
         return true;
     }
 
-    /** Check the cookie and set the associated user_id in the auth_by_cookie session variable.
+    /** Check the cookie and set the associated uid in the auth_by_cookie session variable.
      */
     private function tryCookie()
     {
@@ -81,12 +81,12 @@ class XorgSession extends PlSession
     {
         $res = XDB::query('SELECT  a.uid, a.password
                              FROM  accounts AS a
-                       INNER JOIN  aliases  AS l ON (l.id = a.uid AND l.type != \'homonyme\')
+                       INNER JOIN  aliases  AS l ON (l.uid = a.uid AND l.type != \'homonyme\')
                             WHERE  l.' . $login_type . ' = {?} AND a.state = \'active\'',
                           $login);
         if (list($uid, $password) = $res->fetchOneRow()) {
             $expected_response = sha1("$uname:$password:" . S::v('challenge'));
-            /* XXX: Deprecates len(password) > 10 conversion */
+            /* Deprecates len(password) > 10 conversion. */
             if ($response != $expected_response) {
                 if (!S::logged()) {
                     Platal::page()->trigError('Mot de passe ou nom d\'utilisateur invalide');
@@ -153,7 +153,7 @@ class XorgSession extends PlSession
             }
         }
 
-        $uid = $this->checkPassword($uname, $login, Post::v('response'), (!$redirect && is_numeric($uname)) ? 'id' : 'alias');
+        $uid = $this->checkPassword($uname, $login, Post::v('response'), (!$redirect && is_numeric($uname)) ? 'uid' : 'alias');
         if (!is_null($uid) && S::suid()) {
             if (S::suid('uid') == $uid) {
                 $uid = S::i('uid');
@@ -190,35 +190,8 @@ class XorgSession extends PlSession
             S::set('auth', AUTH_MDP);
         }
 
-        // Retrieves main user properties.
-        /** TODO: Move needed informations to account tables */
-        /** TODO: Currently suppressed data are matricule, promo */
-        /** TODO: Use the User object to fetch all this */
-        $res  = XDB::query("SELECT  a.uid, a.hruid, a.display_name, a.full_name,
-                                    a.sex = 'female' AS femme, a.email_format,
-                                    a.token, FIND_IN_SET('watch', a.flags) AS watch_account,
-                                    UNIX_TIMESTAMP(fp.last_seen) AS banana_last, UNIX_TIMESTAMP(w.last) AS watch_last,
-                                    a.last_version, g.g_account_name IS NOT NULL AS googleapps,
-                                    UNIX_TIMESTAMP(s.start) AS lastlogin, s.host,
-                                    a.is_admin, at.perms
-                              FROM  accounts        AS a
-                        INNER JOIN  account_types   AS at ON(a.type = at.type)
-                        INNER JOIN  watch           AS w  ON(w.uid = a.uid)
-                         LEFT JOIN  forum_profiles  AS fp ON(fp.uid = a.uid)
-                         LEFT JOIN  gapps_accounts  AS g  ON(a.uid = g.l_userid AND g.g_status = 'active')
-                         LEFT JOIN  logger.last_sessions AS ls ON (ls.uid = a.uid)
-                         LEFT JOIN  logger.sessions AS s  ON(s.id = ls.id)
-                             WHERE  a.uid = {?} AND a.state = 'active'", $user->id());
-        if ($res->numRows() != 1) {
-            return false;
-        }
-
-        $sess = $res->fetchOneAssoc();
-        $perms = $sess['perms'];
-        unset($sess['perms']);
-
-        // Loads the data into the real session.
-        $_SESSION = array_merge($_SESSION, $sess);
+        // Loads uid and hruid into the session for developement conveniance.
+        $_SESSION = array_merge($_SESSION, array('uid' => $user->id(), 'hruid' => $user->hruid));
 
         // Starts the session's logger, and sets up the permanent cookie.
         if (S::suid()) {
@@ -235,7 +208,7 @@ class XorgSession extends PlSession
         }
 
         // Finalizes the session setup.
-        $this->makePerms($perms, S::b('is_admin'));
+        $this->makePerms($user->perms, $user->is_admin);
         $this->securityChecks();
         $this->setSkin();
         $this->updateNbNotifs();
@@ -270,9 +243,9 @@ class XorgSession extends PlSession
 
     public function tokenAuth($login, $token)
     {
-        $res = XDB::query('SELECT  a.uid AS user_id, a.hruid
+        $res = XDB::query('SELECT  a.uid, a.hruid
                              FROM  aliases  AS l
-                       INNER JOIN  accounts AS a ON (l.id = a.uid AND a.state = \'active\')
+                       INNER JOIN  accounts AS a ON (l.uid = a.uid AND a.state = \'active\')
                             WHERE  a.token = {?} AND l.alias = {?} AND l.type != \'homonyme\'',
                            $token, $login);
         if ($res->numRows() == 1) {