<?php
/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
+ * Copyright (C) 2003-2008 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
{
// {{{ public static function init
- public static function init()
+ public static function init()
{
S::init();
if (!S::has('uid')) {
try_cookie();
}
- if (check_ip('dangerous') && S::has('uid')) {
+ if ((check_ip('dangerous') && S::has('uid')) || check_account()) {
$_SESSION['log']->log("view_page", $_SERVER['REQUEST_URI']);
}
}
* @param page the calling page (by reference)
*/
public static function doAuthCookie()
+
{
if (S::logged()) {
return true;
}
// }}}
+ // {{{ public static function make_perms()
+
+ public static function &make_perms($perm)
+ {
+ $flags = new FlagSet();
+ if ($perm == 'disabled' || $perm == 'ext') {
+ return $flags;
+ }
+ $flags->addFlag(PERMS_USER);
+ if ($perm == 'admin') {
+ $flags->addFlag(PERMS_ADMIN);
+ }
+ return $flags;
+ }
+
+ // }}}
}
// {{{ function try_cookie()
function start_connexion ($uid, $identified)
{
$res = XDB::query("
- SELECT u.user_id AS uid, prenom, nom, perms, promo, matricule, password, FIND_IN_SET('femme', u.flags) AS femme,
- UNIX_TIMESTAMP(s.start) AS lastlogin, s.host, 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
+ SELECT u.user_id AS uid, 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,
+ nd.display AS display_name, nd.yourself AS yourself_name,
+ nd.firstname AS prenom, nd.lastname AS nom
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 logger.sessions AS s ON (s.uid=u.user_id AND s.suid=0)
- WHERE u.user_id = {?} AND u.perms IN('admin','user')
- ORDER BY s.start DESC
- LIMIT 1", $uid);
+ INNER JOIN profile_names_display AS nd ON (u.user_id = nd.user_id)
+ WHERE u.user_id = {?} AND u.perms IN('admin','user')", $uid);
$sess = $res->fetchOneAssoc();
+ $res = XDB::query("SELECT UNIX_TIMESTAMP(s.start) AS lastlogin, s.host
+ FROM logger.sessions AS s
+ WHERE s.uid = {?} AND s.suid = 0
+ ORDER BY s.start DESC
+ LIMIT 1", $uid);
+ if ($res->numRows()) {
+ $sess = array_merge($sess, $res->fetchOneAssoc());
+ }
$suid = S::v('suid');
if ($suid) {
- $logger = new CoreLogger($uid, $suid);
+ $logger = new CoreLogger($uid, $suid['uid']);
$logger->log("suid_start", S::v('forlife')." by {$suid['uid']}");
$sess['suid'] = $suid;
- $sess['perms'] = $_SESSION['perms'];
} else {
$logger = S::v('log', new CoreLogger($uid));
$logger->log("connexion", Env::v('n'));
$_SESSION = array_merge($_SESSION, $sess);
$_SESSION['log'] = $logger;
$_SESSION['auth'] = ($identified ? AUTH_MDP : AUTH_COOKIE);
+ $_SESSION['perms'] =& XorgSession::make_perms($_SESSION['perms']);
+ $mail_subject = null;
+ if (check_account()) {
+ $mail_subject = "Connexion d'un utilisateur surveillé";
+ }
if (check_ip('unsafe')) {
- send_warning_mail("Une IP surveillee a tente de se connecter");
+ if ($mail_subject) {
+ $mail_subject .= ' - ';
+ }
+ $mail_subject .= "Une IP surveillee a tente de se connecter";
if (check_ip('ban')) {
+ send_warning_mail($mail_subject);
$_SESSION = array();
- global $page;
- $page->trig("Une erreur est survenue lors de la procédure d'authentification. "
+ $_SESSION['perms'] = new FlagSet();
+ $newpage = false;
+ if (!Platal::page()) {
+ require_once 'xorg.inc.php';
+ new_skinned_page('platal/index.tpl');
+ $newpage = true;
+ }
+ Platal::page()->trigError("Une erreur est survenue lors de la procédure d'authentification. "
."Merci de contacter au plus vite "
."<a href='mailto:support@polytechnique.org'>support@polytechnique.org</a>");
+ if ($newpage) {
+ Platal::page()->run();
+ }
return false;
}
}
+ if ($mail_subject) {
+ send_warning_mail($mail_subject);
+ }
set_skin();
+ update_NbNotifs();
check_redirect();
return true;
}
function set_skin()
{
global $globals;
- if (S::logged() && !S::has('skin')) {
+ if (S::logged() && (!S::has('skin') || S::has('suid'))) {
$uid = S::v('uid');
- $res = XDB::query("SELECT skin_tpl
- FROM auth_user_quick AS a
- INNER JOIN skins AS s ON a.skin = s.id
- WHERE user_id = {?} AND skin_tpl != ''", $uid);
- if ($_SESSION['skin'] = $res->fetchOneCell()) {
+ $res = XDB::query("SELECT skin_tpl
+ FROM auth_user_quick AS a
+ INNER JOIN skins AS s ON a.skin = s.id
+ WHERE user_id = {?} AND skin_tpl != ''", $uid);
+ if ($_SESSION['skin'] = $res->fetchOneCell()) {
return;
}
}