X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplsession.php;h=9b6f90e649a9df3628e1a02c261ccffcc1f0f4eb;hb=4d1c62e006bc896e9ddb59d15dc7a7e30f9eb48e;hp=73426fde57dce13ad819c4157612ad646b9c3225;hpb=47fa97fed308292ab5e7bed6f870b39f55747aa8;p=platal.git diff --git a/classes/plsession.php b/classes/plsession.php index 73426fd..9b6f90e 100644 --- a/classes/plsession.php +++ b/classes/plsession.php @@ -1,6 +1,6 @@ checkAuth($level)) { return true; } @@ -159,25 +159,48 @@ abstract class PlSession */ abstract protected function startSessionAs($user, $level); + /** Check authentication with the given token. + * + * Token authentication is a light-weight authentication based on a user-specific token. + * This can be used for protocols that requires a 'cookie'-free authentication, such as + * RSS, iCal registration... + * + * This function returns a valid user object if authentication is successful, or null if + * token mismatch. + */ + 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 (isset($_SESSION['suid'])) { + if (S::suid()) { return false; } - $newsession = array(); - $backup =& $_SESSION; - $_SESSION =& $newsession; + $backup = $_SESSION; + $_SESSION = array(); $this->fillSession(); S::set('suid', $backup); - if (!$this->startSessionAs($user, -1)) { + if (!$this->startSessionAs($user, AUTH_SUID)) { $this->stopSUID(); return false; } + S::set('user', $user); + if (!is_null($perms)) { + $this->makePerms($perms, false); + } return true; } @@ -185,16 +208,20 @@ abstract class PlSession */ public function stopSUID() { - if (!isset($_SESSION['suid'])) { + if (!S::suid()) { return false; } - $_SESSION =& $_SESSION['suid']; + $_SESSION = $_SESSION['suid']; return true; } /*** Thresholds ***/ + /** Minimum level of authentication that is considered as logged. + */ + abstract public function loggedLevel(); + /** Minimum level of authentication that is considered as sure. */ abstract public function sureLevel();