public function __construct()
{
parent::__construct();
- S::bootstrap('perms_backup', new PlFlagSet());
}
public function startAvailableAuth()
{
- if (!(S::v('perms') instanceof PlFlagSet)) {
- S::set('perms', S::v('perms_backup'));
- }
if (!S::logged()) {
$cookie = $this->tryCookie();
if ($cookie == 0) {
return $this->start(AUTH_COOKIE);
- } else if ($cookie == 1 || $cooke == -2) {
+ } else if ($cookie == 1 || $cookie == -2) {
return false;
}
}
*/
private function tryCookie()
{
- Platal::page()->trigError("Trying cookie");
S::kill('auth_by_cookie');
if (Cookie::v('ORGaccess') == '' || !Cookie::has('ORGuid')) {
return -1;
/* We want to do auth... we must have infos from a form.
*/
- if (!Env::has('username') || !Env::has('response') || !S::has('challenge')) {
+ if (!Post::has('username') || !Post::has('response') || !S::has('challenge')) {
return null;
}
S::set('auth', AUTH_COOKIE);
}
unset($_SESSION['log']);
+
+ // Retrieves main user properties.
$res = XDB::query('SELECT u.user_id AS uid, prenom, prenom_ini, nom, nom_ini, nom_usage, perms, promo, promo_sortie,
matricule, password, FIND_IN_SET(\'femme\', u.flags) AS femme,
a.alias AS forlife, a2.alias AS bestalias,
q.core_mail_fmt AS mail_fmt, UNIX_TIMESTAMP(q.banana_last) AS banana_last, q.watch_last, q.core_rss_hash,
- FIND_IN_SET(\'watch\', u.flags) AS watch_account, q.last_version
+ FIND_IN_SET(\'watch\', u.flags) AS watch_account, q.last_version, g.g_account_name IS NOT NULL AS googleapps
FROM auth_user_md5 AS u
INNER JOIN auth_user_quick AS q USING(user_id)
INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type = \'a_vie\')
INNER JOIN aliases AS a2 ON (u.user_id = a2.id AND FIND_IN_SET(\'bestalias\', a2.flags))
+ LEFT JOIN gapps_accounts AS g ON (u.user_id = g.l_userid AND g.g_status = \'active\')
WHERE u.user_id = {?} AND u.perms IN(\'admin\', \'user\')', $uid);
$sess = $res->fetchOneAssoc();
$perms = $sess['perms'];
unset($sess['perms']);
+
+ // Retrieves account usage information (last login, last host).
$res = XDB::query('SELECT UNIX_TIMESTAMP(s.start) AS lastlogin, s.host
FROM logger.sessions AS s
WHERE s.uid = {?} AND s.suid = 0
if ($res->numRows()) {
$sess = array_merge($sess, $res->fetchOneAssoc());
}
- $suid = S::v('suid');
- if ($suid) {
- $logger = S::logger();
- $logger->log("suid_start", S::v('forlife')." by {$suid['uid']}");
- $sess['suid'] = $suid;
+ // Loads the data into the real session.
+ $_SESSION = array_merge($_SESSION, $sess);
+
+ // Starts the session's logger, and sets up the permanent cookie.
+ if (S::has('suid')) {
+ $suid = S::v('suid');
+ $logger = S::logger($uid);
+ $logger->log("suid_start", S::v('forlife') . " by " . $suid['uid']);
} else {
- $logger = S::logger();
- //$logger->log("connexion", Env::v('n'));
+ $logger = S::logger($uid);
setcookie('ORGuid', $uid, (time() + 25920000), '/', '', 0);
- if (Post::v('remember', 'false') == 'true') {
+
+ if (S::i('auth_by_cookie') == $uid || Post::v('remember', 'false') == 'true') {
$cookie = hash_encrypt($sess['password']);
setcookie('ORGaccess', $cookie, (time() + 25920000), '/', '', 0);
- if ($logger) {
+ if ($logger && S::i('auth_by_cookie') != $uid) {
$logger->log("cookie_on");
}
} else {
}
}
- $_SESSION = array_merge($_SESSION, $sess);
+ // Finalizes the session setup.
$this->makePerms($perms);
$this->securityChecks();
$this->setSkin();
- update_NbNotifs();
+ $this->updateNbNotifs();
check_redirect();
+
+ // We should not have to use this private data anymore
+ S::kill('auth_by_cookie');
return true;
}
}
}
+ public function tokenAuth($login, $token)
+ {
+ // FIXME: we broke the session here because some RSS feeds (mainly wiki feeds) require
+ // a valid nome and checks the permissions. When the PlUser object will be ready, we'll
+ // be able to return a simple 'PlUser' object here without trying to alterate the
+ // session.
+ $res = XDB::query('SELECT u.user_id AS uid, u.perms, u.nom, u.nom_usage, u.prenom, u.promo, FIND_IN_SET(\'femme\', u.flags) AS sexe
+ FROM aliases AS a
+ INNER JOIN auth_user_md5 AS u ON (a.id = u.user_id AND u.perms IN ("admin", "user"))
+ INNER JOIN auth_user_quick AS q ON (a.id = q.user_id AND q.core_rss_hash = {?})
+ WHERE a.alias = {?} AND a.type != "homonyme"', $token, $login);
+ if ($res->numRows() == 1) {
+ $sess = $res->fetchOneAssoc();
+ if (!S::has('uid')) {
+ $_SESSION = $sess;
+ $this->makePerms($sess['perms']);
+ return S::i('uid');
+ } else if (S::i('uid') == $sess['uid']) {
+ return S::i('uid');
+ } else {
+ Platal::page()->kill('Invalid state. To be fixed when hruid is ready');
+ }
+ }
+ return null;
+ }
+
public function makePerms($perm)
{
$flags = new PlFlagSet();
if ($perm == 'disabled' || $perm == 'ext') {
S::set('perms', $flags);
- S::set('perms_backup', $flags);
return;
}
$flags->addFlag(PERMS_USER);
$flags->addFlag(PERMS_ADMIN);
}
S::set('perms', $flags);
- S::set('perms_backup', $flags);
}
public function setSkin()
}
}
+ public function loggedLevel()
+ {
+ return AUTH_COOKIE;
+ }
+
public function sureLevel()
{
return AUTH_MDP;
}
+
+
+ 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());
+ }
}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: