X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fxorgsession.php;h=db03eac4446d18c05e13ae2fddc3ad39ddea2f13;hb=cecdf74795e71ed038411915dad5e0dff6ea51fa;hp=fd54234a4ae8f79240a38d092dbdb18d519397aa;hpb=4f247453ac4a734953df893117b72168c60dd22e;p=platal.git diff --git a/classes/xorgsession.php b/classes/xorgsession.php index fd54234..db03eac 100644 --- a/classes/xorgsession.php +++ b/classes/xorgsession.php @@ -1,6 +1,6 @@ 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'); @@ -118,7 +125,7 @@ class XorgSession extends PlSession if (!S::logged()) { S::set('auth', AUTH_COOKIE); } - return User::getSilentWithValues(null, array('user_id' => S::i('auth_by_cookie'))); + return User::getSilentWithUID(S::i('auth_by_cookie')); } @@ -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 = is_numeric($uname) ? 'uid' : 'alias'; } } - $uid = $this->checkPassword($uname, $login, Post::v('response'), (!$redirect && is_numeric($uname)) ? 'id' : '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'); } @@ -175,12 +192,12 @@ class XorgSession extends PlSession S::kill('challenge'); S::logger($uid)->log('auth_ok'); } - return User::getSilentWithValues(null, array('user_id' => $uid)); + return User::getSilentWithUID($uid); } protected function startSessionAs($user, $level) { - if ((!is_null(S::v('user')) && S::v('user')->id() != $user->id()) + if ((!is_null(S::user()) && S::user()->id() != $user->id()) || (S::has('uid') && S::i('uid') != $user->id())) { return false; } else if (S::has('uid')) { @@ -190,31 +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, 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()); - $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, 'token' => $user->token)); // Starts the session's logger, and sets up the permanent cookie. if (S::suid()) { @@ -231,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(); @@ -242,21 +236,6 @@ class XorgSession extends PlSession return true; } - /** Start a session without authentication data for the given user. - * This is used to identify the user after his registration, to be - * removed after rewriting registration procedure. - * XXX: Temporary - */ - public function startWeakSession($user) - { - if (!$this->startSessionAs($user, AUTH_MDP)) { - $this->destroy(); - return false; - } - S::set('auth', AUTH_MDP); - return true; - } - private function securityChecks() { $mail_subject = array(); @@ -281,11 +260,10 @@ class XorgSession extends PlSession public function tokenAuth($login, $token) { - $res = XDB::query('SELECT a.uid AS user_id, a.hruid - FROM aliases AS l - INNER JOIN accounts AS a ON (l.id = a.uid AND a.state = \'active\') - WHERE a.token = {?} AND l.alias = {?} AND l.type != \'homonyme\'', - $token, $login); + $res = XDB::query('SELECT a.uid, a.hruid + FROM accounts AS a + WHERE a.token = {?} AND a.hruid = {?} AND a.state = \'active\'', + $token, $login); if ($res->numRows() == 1) { return new User(null, $res->fetchOneAssoc()); } @@ -322,8 +300,9 @@ class XorgSession extends PlSession public function updateNbNotifs() { require_once 'notifs.inc.php'; - $n = select_notifs(false, S::i('uid'), S::v('watch_last'), false); - S::set('notifs', $n->numRows()); + $user = S::user(); + $n = Watch::getCount($user); + S::set('notifs', $n); } public function setAccessCookie($replace = false, $log = true) {