<?php
/***************************************************************************
- * Copyright (C) 2003-2008 Polytechnique.org *
+ * Copyright (C) 2003-2009 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
class XorgSession extends PlSession
{
+ const INVALID_USER = -2;
+ const NO_COOKIE = -1;
+ const COOKIE_SUCCESS = 0;
+ const INVALID_COOKIE = 1;
+
public function __construct()
{
parent::__construct();
public function startAvailableAuth()
{
if (!S::logged()) {
- $cookie = $this->tryCookie();
- if ($cookie == 0) {
- return $this->start(AUTH_COOKIE);
- } else if ($cookie == 1 || $cookie == -2) {
+ switch ($this->tryCookie()) {
+ case self::COOKIE_SUCCESS:
+ if (!$this->start(AUTH_COOKIE)) {
+ return false;
+ }
+ break;
+
+ case self::INVALID_USER:
+ case self::INVALID_COOKIE:
return false;
}
}
{
S::kill('auth_by_cookie');
if (Cookie::v('access') == '' || !Cookie::has('uid')) {
- return -1;
+ return self::NO_COOKIE;
}
$res = XDB::query('SELECT uid, password
Cookie::i('uid'));
if ($res->numRows() != 0) {
list($uid, $password) = $res->fetchOneRow();
- $expected_value = sha1($password);
- if ($expected_value == Cookie::v('access')) {
+ if (sha1($password) == Cookie::v('access')) {
S::set('auth_by_cookie', $uid);
- return 0;
+ return self::COOKIE_SUCCESS;
} else {
- return 1;
+ return self::INVALID_COOKIE;
}
}
- return -2;
+ return self::INVALID_USER;
}
private function checkPassword($uname, $login, $response, $login_type)
// Retrieves main user properties.
/** TODO: Move needed informations to account tables */
/** TODO: Currently suppressed data are matricule, promo */
- /** TODO: Data to move are: banana_last, watch_last, last_version */
/** TODO: Use the User object to fetch all this */
- $res = XDB::query("SELECT a.uid, a.hruid, a.display_name, a.full_name, a.password,
+ $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, q.watch_last,
- q.last_version, g.g_account_name IS NOT NULL AS googleapps,
+ 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 auth_user_quick AS q ON(a.uid = q.user_id)
+ 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)
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();
public function setSkin()
{
if (S::logged() && (!S::has('skin') || S::suid())) {
- $uid = S::v('uid');
$res = XDB::query('SELECT skin_tpl
FROM accounts AS a
INNER JOIN skins AS s on (a.skin = s.id)
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) {
if (S::suid() || ($replace && !Cookie::blank('access'))) {
return;
}
- Cookie::set('access', sha1(S::v('password')), 300, true);
+ Cookie::set('access', sha1(S::user()->password()), 300, true);
if ($log) {
S::logger()->log('cookie_on');
}