X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fxorgsession.php;h=a6ed341c0112370f91c8baf41b8d4c6de2048ae0;hb=675f3174fd4c77a5ac9a419f3fc38875d56e92e9;hp=011b6b52a97eb39492ff121b233d90fcef41f43a;hpb=34465ab035104f739a54ec62660f04f874448627;p=platal.git diff --git a/classes/xorgsession.php b/classes/xorgsession.php index 011b6b5..a6ed341 100644 --- a/classes/xorgsession.php +++ b/classes/xorgsession.php @@ -79,14 +79,21 @@ class XorgSession extends PlSession private function checkPassword($uname, $login, $response, $login_type) { - $res = XDB::query('SELECT a.uid, a.password - FROM accounts AS a - INNER JOIN aliases AS l ON (l.uid = a.uid AND l.type != \'homonyme\') - WHERE l.' . $login_type . ' = {?} AND a.state = \'active\'', - $login); + if ($login_type == 'alias') { + $res = XDB::query('SELECT a.uid, a.password + FROM accounts AS a + INNER JOIN aliases AS l ON (l.uid = a.uid AND l.type != \'homonyme\') + WHERE l.alias = {?} AND a.state = \'active\'', + $login); + } else { + $res = XDB::query('SELECT uid, password + FROM accounts + WHERE ' . $login_type . ' = {?}', + $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'); @@ -132,10 +139,11 @@ class XorgSession extends PlSession */ if (S::suid()) { $login = $uname = S::suid('uid'); + $loginType = 'uid'; $redirect = false; } else { - $uname = Env::v('username'); - if (Env::v('domain') == "alias") { + $uname = Post::v('username'); + if (Post::s('domain') == "alias") { $res = XDB::query('SELECT redirect FROM virtual INNER JOIN virtual_redirect USING(vid) @@ -147,13 +155,19 @@ class XorgSession extends PlSession } else { $login = ''; } + $loginType = 'alias'; + } else if (Post::s('domain') == "ax") { + $login = $uname; + $redirect = false; + $loginType = 'hruid'; } else { $login = $uname; $redirect = false; + $loginType = 'alias'; } } - $uid = $this->checkPassword($uname, $login, Post::v('response'), (!$redirect && is_numeric($uname)) ? 'uid' : 'alias'); + $uid = $this->checkPassword($uname, $login, Post::v('response'), $loginType); if (!is_null($uid) && S::suid()) { if (S::suid('uid') == $uid) { $uid = S::i('uid'); @@ -165,8 +179,11 @@ class XorgSession extends PlSession S::set('auth', AUTH_MDP); if (!S::suid()) { if (Post::has('domain')) { - if (($domain = Post::v('domain', 'login')) == 'alias') { + $domain = Post::v('domain', 'login'); + if ($domain == 'alias') { Cookie::set('domain', 'alias', 300); + } else if ($domain == 'ax') { + Cookie::set('domain', 'ax', 300); } else { Cookie::kill('domain'); } @@ -190,35 +207,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) - LEFT 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 log_last_sessions AS ls ON (ls.uid = a.uid) - LEFT JOIN log_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 +225,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();