From: Florent Bruneau Date: Mon, 22 Dec 2008 16:36:32 +0000 (+0100) Subject: Some API breakage: X-Git-Tag: core/1.0.1~50 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=7adcbe0e8cd74f157fa10b175208c8efa645cd94;p=platal.git Some API breakage: * plsession officially contains an abstract *protected* method named makePerms. * startSUID takes an optionnal argument with destination permission level. * Adds S::b($key) to get a session variable as a boolean. Signed-off-by: Florent Bruneau --- diff --git a/classes/plsession.php b/classes/plsession.php index 688f5f5..d4549c9 100644 --- a/classes/plsession.php +++ b/classes/plsession.php @@ -171,12 +171,21 @@ abstract class PlSession */ abstract public function tokenAuth($login, $token); + /** Set the permissions to the given flagset. + * + * This function sets S::set('perms') with a flagset represeting the combination of + * $perms and $is_admin. + * + * $perms is an abstract object representing the permissions. + * $is_admin is a boolean, true if the current user has site-administration rights. + */ + abstract protected function makePerms($perms, $is_admin); /*** SUID management ***/ /** Start a new SUID session. */ - public function startSUID($user) + public function startSUID($user, $perms = null) { if (S::has('suid')) { return false; @@ -190,6 +199,9 @@ abstract class PlSession return false; } S::set('user', $user); + if (!is_null($perms)) { + $this->makePerms($perms, false); + } return true; } diff --git a/classes/s.php b/classes/s.php index e14c440..ff29982 100644 --- a/classes/s.php +++ b/classes/s.php @@ -49,6 +49,11 @@ class S return (string)S::v($key, $default); } + public static function b($key, $default = false) + { + return (bool)S::v($key, $default); + } + public static function i($key, $default = 0) { $i = S::v($key, $default); diff --git a/modules/core.php b/modules/core.php index 42b0c4c..44b4595 100644 --- a/modules/core.php +++ b/modules/core.php @@ -129,8 +129,7 @@ class CoreModule extends PLModule if (isset($_SESSION['log'])) { S::logger()->log("suid_start", "login by " . S::user()->login()); } - Platal::session()->startSUID(S::i('uid')); - Platal::session()->makePerms($level); + Platal::session()->startSUID(S::i('uid'), $level); pl_redirect('/'); }