From 2ab3486b89b57e612d6f412afa97f7442a0e2ac0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Tue, 20 Jul 2010 23:47:00 +0200 Subject: [PATCH] Removes deprecated variables from session, adds variables into user object for session needs. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/user.php | 20 ++++++++++++++++---- classes/xnetsession.php | 2 +- classes/xorgsession.php | 33 +++------------------------------ include/banana/forum.inc.php | 4 ++-- include/banana/hooks.inc.php | 2 +- include/security.inc.php | 2 +- modules/admin.php | 2 +- modules/carnet.php | 4 ++-- modules/email.php | 6 +++--- modules/events.php | 4 ++-- modules/platal.php | 5 ++--- modules/xnetgrp.php | 2 +- templates/admin/wiki.tpl | 2 +- templates/carnet/index.tpl | 4 ++-- templates/carnet/mescontacts.tpl | 6 +++--- templates/carnet/panel.tpl | 4 ++-- templates/emails/imap_register.tpl | 2 +- templates/events/index.tpl | 16 ++++++++-------- templates/marketing/broken.tpl | 4 ++-- templates/platal/filrss.tpl | 6 +++--- templates/platal/preferences.tpl | 4 ++-- templates/skin/common.menu.tpl | 2 +- templates/xnetgrp/asso.tpl | 4 ++-- templates/xnetgrp/inscrire.tpl | 2 +- templates/xnetlists/index.tpl | 4 ++-- 25 files changed, 65 insertions(+), 81 deletions(-) diff --git a/classes/user.php b/classes/user.php index f4f68c3..32c3aa1 100644 --- a/classes/user.php +++ b/classes/user.php @@ -187,9 +187,10 @@ class User extends PlUser IF(a.state = \'active\', at.perms, \'\') AS perms, a.email_format, a.is_admin, a.state, a.type, a.skin, FIND_IN_SET(\'watch\', a.flags) AS watch, a.comment, - a.weak_password IS NOT NULL AS weak_access, - a.token IS NOT NULL AS token_access, - (e.email IS NULL AND NOT FIND_IN_SET(\'googleapps\', eo.storage)) AND a.state != \'pending\' AS lost + a.weak_password IS NOT NULL AS weak_access, g.g_account_name IS NOT NULL AS googleapps, + a.token IS NOT NULL AS token_access, a.token, a.last_version, + (e.email IS NULL AND NOT FIND_IN_SET(\'googleapps\', eo.storage)) AND a.state != \'pending\' AS lost, + UNIX_TIMESTAMP(s.start) AS lastlogin, s.host, UNIX_TIMESTAMP(fp.last_seen) AS banana_last ' . $fields . ' FROM accounts AS a INNER JOIN account_types AS at ON (at.type = a.type) @@ -198,6 +199,10 @@ class User extends PlUser LEFT JOIN aliases AS ah ON (ah.uid = a.uid AND ah.type = \'homonyme\') LEFT JOIN emails AS e ON (e.uid = a.uid AND e.flags = \'active\') LEFT JOIN email_options AS eo ON (eo.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) + LEFT JOIN forum_profiles AS fp ON (fp.uid = a.uid) ' . $joins . ' WHERE a.uid IN (' . implode(', ', $uids) . ') GROUP BY a.uid @@ -271,6 +276,14 @@ class User extends PlUser return $this->profile()->lastName(); } + public function displayName() + { + if (!$this->hasProfile()) { + return $this->display_name; + } + return $this->profile()->yourself; + } + public function fullName($with_promo = false) { if (!$this->hasProfile()) { @@ -444,7 +457,6 @@ class User extends PlUser $this->email_format = $format; } - /** Get watch informations */ private function fetchWatchData() diff --git a/classes/xnetsession.php b/classes/xnetsession.php index 0ebc2e6..5d9e07c 100644 --- a/classes/xnetsession.php +++ b/classes/xnetsession.php @@ -107,7 +107,7 @@ class XnetSession extends XorgSession LIMIT 1", $user->id()); $sess = $res->fetchOneAssoc(); $_SESSION = array_merge($_SESSION, $sess); - $this->makePerms(S::s('perms'), S::b('is_admin')); + $this->makePerms(S::s('perms'), S::user()->is_admin); S::kill('challenge'); S::kill('loginX'); S::kill('may_update'); diff --git a/classes/xorgsession.php b/classes/xorgsession.php index 4224920..02e34e4 100644 --- a/classes/xorgsession.php +++ b/classes/xorgsession.php @@ -190,35 +190,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, - 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 +208,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(); diff --git a/include/banana/forum.inc.php b/include/banana/forum.inc.php index 6a6a869..b43ab28 100644 --- a/include/banana/forum.inc.php +++ b/include/banana/forum.inc.php @@ -101,7 +101,7 @@ class ForumsBanana extends Banana $time = null; if (!is_null($this->params) && isset($this->params['updateall'])) { $time = intval($this->params['updateall']); - S::set('banana_last', $time); + S::user()->banana_last = $time; } $infos = $this->fetchProfile(); @@ -119,7 +119,7 @@ class ForumsBanana extends Banana Banana::$profile['signature'] = $infos['sig']; Banana::$profile['display'] = $infos['threads']; Banana::$profile['autoup'] = $infos['maj']; - Banana::$profile['lastnews'] = S::v('banana_last'); + Banana::$profile['lastnews'] = S::user()->banana_last; Banana::$profile['subscribe'] = $req->fetchColumn(); Banana::$tree_unread = $infos['tree_unread']; Banana::$tree_read = $infos['tree_read']; diff --git a/include/banana/hooks.inc.php b/include/banana/hooks.inc.php index 9d42694..c08c983 100644 --- a/include/banana/hooks.inc.php +++ b/include/banana/hooks.inc.php @@ -77,7 +77,7 @@ function hook_platalRSS($group) } else { $group = ''; } - return '/rss/' . $group . S::v('hruid') . '/' . S::s('token') . '/rss.xml'; + return '/rss/' . $group . S::v('hruid') . '/' . S::user()->token . '/rss.xml'; } function hook_platalMessageLink($params) diff --git a/include/security.inc.php b/include/security.inc.php index 3def558..47b38da 100644 --- a/include/security.inc.php +++ b/include/security.inc.php @@ -78,7 +78,7 @@ function check_email($email, $message) function check_account() { - return S::v('watch_account'); + return S::user()->watch; } function check_redirect($red = null) diff --git a/modules/admin.php b/modules/admin.php index 4dfeb8a..624cb3f 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -1140,7 +1140,7 @@ class AdminModule extends PLModule { if (S::hasAuthToken()) { $page->setRssLink('Changement Récents', - '/Site/AllRecentChanges?action=rss&user=' . S::v('hruid') . '&hash=' . S::v('token')); + '/Site/AllRecentChanges?action=rss&user=' . S::v('hruid') . '&hash=' . S::user()->token); } // update wiki perms diff --git a/modules/carnet.php b/modules/carnet.php index 1d065af..276fabf 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -45,7 +45,7 @@ class CarnetModule extends PLModule return; } $page->setRssLink('Polytechnique.org :: Carnet', - '/carnet/rss/'.S::v('hruid').'/'.S::v('token').'/rss.xml'); + '/carnet/rss/' . S::v('hruid') . '/' . S::user()->token . '/rss.xml'); } function handler_index(&$page) @@ -275,7 +275,7 @@ class CarnetModule extends PLModule // For XSRF protection, checks both the normal xsrf token, and the special RSS token. // It allows direct linking to contact adding in the RSS feed. - if (Env::v('action') && Env::v('token') !== S::v('token')) { + if (Env::v('action') && Env::v('token') !== S::user()->token) { S::assert_xsrf_token(); } switch (Env::v('action')) { diff --git a/modules/email.php b/modules/email.php index 5fd93e9..81fb7ba 100644 --- a/modules/email.php +++ b/modules/email.php @@ -619,13 +619,13 @@ class EmailModule extends PLModule $storage = new EmailStorage(S::user(), 'imap'); $storage->activate(); $page->assign('ok', true); - $page->assign('prenom', S::v('prenom')); - $page->assign('sexe', S::v('femme')); + $page->assign('yourself', S::user()->displayName()); + $page->assign('sexe', S::user()->isFemale()); } else if (!S::logged() && $user) { $storage = new EmailStorage($user, 'imap'); $storage->activate(); $page->assign('ok', true); - $page->assign('prenom', $user->displayName()); + $page->assign('yourself', $user->displayName()); $page->assign('sexe', $user->isFemale()); } } diff --git a/modules/events.php b/modules/events.php index eebfa82..035f274 100644 --- a/modules/events.php +++ b/modules/events.php @@ -40,7 +40,7 @@ class EventsModule extends PLModule { global $globals; // Add a new special tip when changing plat/al version - if ($globals->version != S::v('last_version') && is_null($exclude)) { + if ($globals->version != S::user()->last_version && is_null($exclude)) { XDB::execute('UPDATE accounts SET last_version = {?} WHERE uid = {?}', @@ -126,7 +126,7 @@ class EventsModule extends PLModule // Direct link to the RSS feed, when available. if (S::hasAuthToken()) { $page->setRssLink('Polytechnique.org :: News', - '/rss/'.S::v('hruid') .'/'.S::v('token').'/rss.xml'); + '/rss/' . S::v('hruid') . '/' . S::user()->token . '/rss.xml'); } // Hide the read event, and reload the page to get to the next event. diff --git a/modules/platal.php b/modules/platal.php index 2ad9317..e24ce58 100644 --- a/modules/platal.php +++ b/modules/platal.php @@ -113,10 +113,10 @@ class PlatalModule extends PLModule function __set_rss_state($state) { if ($state) { - S::set('token', rand_url_id(16)); + S::user()->token = rand_url_id(16); XDB::execute('UPDATE accounts SET token = {?} - WHERE uid = {?}', S::s('token'), S::i('uid')); + WHERE uid = {?}', S::user()->token, S::i('uid')); } else { S::kill('token'); XDB::execute('UPDATE accounts @@ -133,7 +133,6 @@ class PlatalModule extends PLModule if (Post::has('email_format')) { $fmt = Post::s('email_format'); S::user()->setEmailFormat($fmt); - S::set('email_format', $fmt); } if (Post::has('rss')) { diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index e4449a0..6036310 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -130,7 +130,7 @@ class XnetGrpModule extends PLModule $platal->ns . "rss/rss.xml"); } else { $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News", - $platal->ns . 'rss/'.S::v('hruid') .'/'.S::v('token').'/rss.xml'); + $platal->ns . 'rss/' . S::v('hruid') . '/' . S::user()->token . '/rss.xml'); } $page->assign('articles', $arts); diff --git a/templates/admin/wiki.tpl b/templates/admin/wiki.tpl index abe4194..dd8047d 100644 --- a/templates/admin/wiki.tpl +++ b/templates/admin/wiki.tpl @@ -68,7 +68,7 @@ {/literal}

- {icon name=feed title='fil rss'} + {icon name=feed title='fil rss'} {icon name=magnifier} Voir les changements récents

diff --git a/templates/carnet/index.tpl b/templates/carnet/index.tpl index b1d0630..b00d7fa 100644 --- a/templates/carnet/index.tpl +++ b/templates/carnet/index.tpl @@ -53,8 +53,8 @@
- {if $smarty.session.token} - + {if $smarty.session.user->token} + {icon name=feed title='fil rss'} {else} diff --git a/templates/carnet/mescontacts.tpl b/templates/carnet/mescontacts.tpl index c3be38b..d3231d2 100644 --- a/templates/carnet/mescontacts.tpl +++ b/templates/carnet/mescontacts.tpl @@ -62,10 +62,10 @@
  • Le calendrier des anniversaires : - + {icon name=calendar_view_day title='Anniversaires au format iCal'} - + {icon name=outlook title='Anniversaires au format Outlook'}
  • @@ -75,7 +75,7 @@ {icon name=vcard title='Carte de visite au format vCard'} (sans les photos) - + {icon name=outlook title='Contacts au format Outlook'} diff --git a/templates/carnet/panel.tpl b/templates/carnet/panel.tpl index eed3763..db12e22 100644 --- a/templates/carnet/panel.tpl +++ b/templates/carnet/panel.tpl @@ -38,8 +38,8 @@ Il faut pour cela se rendre sur la page de configuration

    diff --git a/templates/emails/imap_register.tpl b/templates/emails/imap_register.tpl index 2975e84..af8c048 100644 --- a/templates/emails/imap_register.tpl +++ b/templates/emails/imap_register.tpl @@ -22,7 +22,7 @@ {if $ok}

    - {if $sexe}Chère{else}Cher{/if} {$prenom}, + {if $sexe}Chère{else}Cher{/if} {$yourself},

    diff --git a/templates/events/index.tpl b/templates/events/index.tpl index 5a5744c..83eb602 100644 --- a/templates/events/index.tpl +++ b/templates/events/index.tpl @@ -27,17 +27,17 @@ {else}

    -Bienvenue {$smarty.session.display_name}{if $birthday} +Bienvenue {$smarty.session.user->displayName()}{if $birthday}  et joyeux anniversaire de la part de toute l'équipe ! {else}, {/if}

    -{if $smarty.session.host} +{if $smarty.session.user->host}
    {if $birthday}T{else}t{/if}a connexion précédente date du - {$smarty.session.lastlogin|date_format:"%x, %X"} - depuis la machine {$smarty.session.host}. + {$smarty.session.user->lastlogin|date_format:"%x, %X"} + depuis la machine {$smarty.session.user->host}.
    {/if} @@ -52,8 +52,8 @@ Bienvenue {$smarty.session.display_name}{if $birthday}
    {if $smarty.foreach.events.first} - {if $smarty.session.token} - + {if $smarty.session.user->token} + {icon name=feed title='fil rss'} {else} @@ -92,8 +92,8 @@ Bienvenue {$smarty.session.display_name}{if $birthday} {if !$has_evts}
    - {if $smarty.session.token} - + {if $smarty.session.user->token} + {icon name=feed title='fil rss'} {else} diff --git a/templates/marketing/broken.tpl b/templates/marketing/broken.tpl index f620df9..dcf3bed 100644 --- a/templates/marketing/broken.tpl +++ b/templates/marketing/broken.tpl @@ -48,13 +48,13 @@ {elseif $user->last}

    {$user->fullName()} a encore des adresses de redirection actives malgré des pannes détectées sur certaines d'entre elles. Si - tu es sûr{if $smarty.session.femme}e{/if} que son adresse Polytechnique.org est en panne, tu peux proposer une nouvelle + tu es sûr{if $smarty.session.user->gender}e{/if} que son adresse Polytechnique.org est en panne, tu peux proposer une nouvelle adresse email à ajouter à ses redirections. Merci d'ajouter un commentaire pour nous indiquer la raison de cette proposition.

    {else}

    Nous n'avons actuellement enregistré aucune panne sur les adresses de redirection de {$user->fullName()}. Si tu es - sûr{if $smarty.session.femme}e{/if} que son adresse de redirection actuelle est en panne, tu peux nous proposer + sûr{if $smarty.session.user->gender}e{/if} que son adresse de redirection actuelle est en panne, tu peux nous proposer une nouvelle adresse, accompagnée d'un commentaire nous expliquant les raisons exactes de cette proposition.

    {/if} diff --git a/templates/platal/filrss.tpl b/templates/platal/filrss.tpl index d25c94c..83d5d24 100644 --- a/templates/platal/filrss.tpl +++ b/templates/platal/filrss.tpl @@ -22,7 +22,7 @@

    Fil RSS

    -{if !$smarty.session.token} +{if !$smarty.session.user->token}

    Tu viens de cliquer sur le lien d'activation des fils RSS. Les fils RSS du site ne sont pas activés dans tes préférences. @@ -52,11 +52,11 @@ En voici les adresses :

    diff --git a/templates/platal/preferences.tpl b/templates/platal/preferences.tpl index 05b8d4e..d7ba64a 100644 --- a/templates/platal/preferences.tpl +++ b/templates/platal/preferences.tpl @@ -61,7 +61,7 @@

    - {if $smarty.session.email_format eq html} + {if $smarty.session.user->email_format eq html}

    Recevoir les emails en format texte

    @@ -83,7 +83,7 @@

    - {if $smarty.session.token} + {if $smarty.session.user->token} Désactiver les fils rss {else} Activer les fils rss diff --git a/templates/skin/common.menu.tpl b/templates/skin/common.menu.tpl index 2ab77f8..9b61516 100644 --- a/templates/skin/common.menu.tpl +++ b/templates/skin/common.menu.tpl @@ -55,7 +55,7 @@ -{if $smarty.session.googleapps} +{if $smarty.session.user->googleapps} {/if} diff --git a/templates/xnetgrp/asso.tpl b/templates/xnetgrp/asso.tpl index 35e08c6..e3a0add 100644 --- a/templates/xnetgrp/asso.tpl +++ b/templates/xnetgrp/asso.tpl @@ -108,8 +108,8 @@
    - {if $smarty.session.token} - + {if $smarty.session.user->token} + {icon name=feed title='fil rss'} {else} diff --git a/templates/xnetgrp/inscrire.tpl b/templates/xnetgrp/inscrire.tpl index f20f07e..3553465 100644 --- a/templates/xnetgrp/inscrire.tpl +++ b/templates/xnetgrp/inscrire.tpl @@ -60,7 +60,7 @@ {elseif $smarty.post.inscrire}

    -Ta demande d'inscription a bien été envoyée ! Tu seras averti{if $smarty.session.femme}e{/if} par email de la suite qui lui sera donnée. +Ta demande d'inscription a bien été envoyée ! Tu seras averti{if $smarty.session.user->gender}e{/if} par email de la suite qui lui sera donnée.

    [Retour à la page d'accueil de {$asso->nom}]

    diff --git a/templates/xnetlists/index.tpl b/templates/xnetlists/index.tpl index 678a6f3..df0da12 100644 --- a/templates/xnetlists/index.tpl +++ b/templates/xnetlists/index.tpl @@ -45,7 +45,7 @@ par les administrateurs avant d'être transmis aux membres de la liste. Une lis l'accord préalable des responsables du groupe.

    -La dernière colonne du tableau t'indique si tu es inscrit{if $smarty.session.femme}e{/if} ou non à +La dernière colonne du tableau t'indique si tu es inscrit{if $smarty.session.user->gender}e{/if} ou non à la liste. Dans le premier cas, une croix rouge te permet de te désabonner. Dans le second cas, une croix verte te permet de t'inscrire, après accord des responsables si l'inscription est modérée.

    @@ -101,7 +101,7 @@ croix verte te permet de t'inscrire, après accord des responsables si l'inscrip

    -{icon name=wrench title="Modérateur"} tu es {if $smarty.session.femme}modératrice{else}moderateur{/if} sur cette liste.
    +{icon name=wrench title="Modérateur"} tu es {if $smarty.session.user->gender}modératrice{else}moderateur{/if} sur cette liste.
    {icon name=weather_cloudy title="Liste privée"} cette liste est invisible aux non-membres de la liste. S'en désabonner t'empêcherait de t'y réabonner par la suite sans l'aide d'un administrateur.

    -- 2.1.4