X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fs.php;h=d436bf1e6ddd11c663a92575268de78c86d7b501;hb=f23d33e1b114e9032b4b966baebdeb14b4215313;hp=c2a10e8b6a17ee2d3048b91ccf2d328f337f1e29;hpb=6995a9b92e68cffcf7a8375080f9e5a210acf0af;p=platal.git diff --git a/classes/s.php b/classes/s.php index c2a10e8..d436bf1 100644 --- a/classes/s.php +++ b/classes/s.php @@ -1,6 +1,6 @@ isValid($uid)) { + global $platal; + if (S::has('suid')) { + $suid = S::v('suid'); + S::set('log', $platal->buildLogger(S::i('uid', $uid), $suid['uid'])); + } else if (S::has('uid') || $uid) { + S::set('log', $platal->buildLogger(S::i('uid', $uid))); + } else { + S::set('log', PlLogger::dummy($uid)); + } + } + return S::v('log'); + } + + /** User object storage and accessor. The user object (an instance of the + * local subclass of PlUser) is currently stored as a S class variable, and + * not as a session variable, so as to avoid bloating the global on-disk + * session. + * TODO: When all the codebase will use S::user() as the only source for + * user ids, fullname/displayname, and forlife/bestalias, S::$user should + * move into the php session (and data it helds should be removed from + * the php session). */ + private static $user = null; + public static function &user($forceFetch = false) + { + if (($forceFetch || self::$user == null) && class_exists('User')) { + if (S::has('user') && S::v('user') instanceof User) { + self::$user = S::v('user'); + } else { + self::$user = User::getSilentWithValues(S::i('uid'), $_SESSION); + } + } + return self::$user; + } + + public static function changeSession(array $newSession) + { + $oldSession = $_SESSION; + $_SESSION = $newSession; + self::$user = null; + return $oldSession; + } + + public static function logged() + { + return S::i('auth', AUTH_PUBLIC) >= Platal::session()->loggedLevel(); + } + + public static function identified() + { + return S::i('auth', AUTH_PUBLIC) >= Platal::session()->sureLevel(); + } + + public static function admin() + { + return Platal::session()->checkPerms(PERMS_ADMIN); + } + + public static function suid($field = null, $default = null) + { + if (is_null($field)) { + return !S::blank('suid'); + } else { + $suid = S::v('suid', array()); + if (!empty($suid) && isset($suid[$field])) { + return $suid[$field]; + } else { + return $default; + } + } + } + + // Anti-XSRF protections. + public static function has_xsrf_token() + { + return S::has('xsrf_token') && S::v('xsrf_token') == Env::v('token'); + } + + public static function assert_xsrf_token() + { + if (!S::has_xsrf_token()) { + Platal::page()->kill('L\'opération n\'a pas pu aboutir, merci de réessayer.'); + } + } + + public static function hasAuthToken() + { + return !S::blank('token'); + } + + public static function rssActivated() + { + // XXX: Deprecated, to be replaced by S::hasToken() + return S::has('core_rss_hash') && S::v('core_rss_hash'); + } } +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>