X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fxnet%2Fsession.inc.php;h=83e3a72e3c556a7ab4bb9c443bd26afe17b43eb9;hb=cab0809050d58f8484608e91f7555ebd69dcb451;hp=c234e3ff802c118d4bcb5091ca131d5f126468c4;hpb=cdfe0063c9b6b0fad10dd6d97ae2f25010e3620c;p=platal.git diff --git a/include/xnet/session.inc.php b/include/xnet/session.inc.php index c234e3f..83e3a72 100644 --- a/include/xnet/session.inc.php +++ b/include/xnet/session.inc.php @@ -23,49 +23,40 @@ require_once('platal/session.inc.php'); // {{{ class XorgSession -class XnetSession extends DiogenesCoreSession +class XnetSession { - // {{{ function XnetSession() - - function XnetSession() - { - $this->DiogenesCoreSession(); - } - - // }}} // {{{ function init - + function init() { global $globals; - @session_start(); - if (!Session::has('session')) { - $_SESSION['session'] = new XnetSession; - } - if (!logged()) { + S::init(); + + $_SESSION['session'] = new XnetSession; + + if (!S::logged()) { // prevent connexion to be linked to deconnexion - if (($i = strpos($_SERVER['REQUEST_URI'], 'deconnexion.php')) !== false) + if (($i = strpos($_SERVER['REQUEST_URI'], 'exit')) !== false) $returl = "http://{$_SERVER['SERVER_NAME']}".substr($_SERVER['REQUEST_URI'], 0, $i); else $returl = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"; $url = "https://www.polytechnique.org/auth-groupex.php"; $url .= "?session=" . session_id(); - $url .= "&challenge=" . $_SESSION['session']->challenge; - $url .= "&pass=" . md5($_SESSION['session']->challenge . $globals->xnet->secret); + $url .= "&challenge=" . S::v('challenge'); + $url .= "&pass=" . md5(S::v('challenge') . $globals->xnet->secret); $url .= "&url=".urlencode($returl); - $_SESSION['session']->loginX = $url; + $_SESSION['loginX'] = $url; } } - + // }}} // {{{ function destroy() - + function destroy() { - @session_destroy(); - unset($_SESSION); + S::destroy(); XnetSession::init(); } - + // }}} // {{{ function doAuth() @@ -75,17 +66,14 @@ class XnetSession extends DiogenesCoreSession */ function doAuth(&$page) { - global $globals; - if (identified()) { // ok, c'est bon, on n'a rien à faire + if (S::identified()) { // ok, c'est bon, on n'a rien à faire return true; } if (Get::has('auth')) { - return $this->doAuthX($page); - } elseif (Post::has('challenge') && Post::has('username') && Post::has('response')) { - return $this->doAuthOther($page); + return XnetSession::doAuthX($page); } else { - $this->doLogin($page); + XnetSession::doLogin($page); } } @@ -95,11 +83,11 @@ class XnetSession extends DiogenesCoreSession function doAuthX(&$page) { global $globals; - if (md5('1'.$this->challenge.$globals->xnet->secret.Get::getInt('uid').'1') != Get::get('auth')) { + if (md5('1'.S::v('challenge').$globals->xnet->secret.Get::getInt('uid').'1') != Get::get('auth')) { $page->kill("Erreur d'authentification avec polytechnique.org !"); } - $res = $globals->xdb->query(" + $res = XDB::query(" SELECT u.user_id AS uid, prenom, nom, perms, promo, password, FIND_IN_SET('femme', u.flags) AS femme, a.alias AS forlife, a2.alias AS bestalias, q.core_mail_fmt AS mail_fmt, q.core_rss_hash FROM auth_user_md5 AS u @@ -110,8 +98,8 @@ class XnetSession extends DiogenesCoreSession LIMIT 1", Get::getInt('uid')); $_SESSION = array_merge($_SESSION, $res->fetchOneAssoc()); $_SESSION['auth'] = AUTH_MDP; - unset($this->challenge); - unset($this->loginX); + S::kill('challenge'); + S::kill('loginX'); Get::kill('auth'); Get::kill('uid'); $args = array(); @@ -122,23 +110,10 @@ class XnetSession extends DiogenesCoreSession } // }}} - // {{{ doAuthOther - - function doAuthOther(&$page) { - if (Post::has('challenge') && Post::has('username') && Post::has('response')) { - $username = Post::get('username'); - } - $this->doLogin($page); - } - - // }}} // {{{ doLogin function doLogin(&$page) { - // login for non-x has been disabled, so don't need this js anymore - //$page->addJsLink('javascript/do_challenge_response.js.php'); - $page->assign("xorg_tpl", "xnet/login.tpl"); - $page->run(); + redirect(S::v('loginX')); } // }}} @@ -150,11 +125,11 @@ class XnetSession extends DiogenesCoreSession function may_update() { global $globals; if (!$globals->asso('id')) { return false; } - if (has_perms()) { return true; } - $res = $globals->xdb->query( + if (S::has_perms()) { return true; } + $res = XDB::query( "SELECT perms FROM groupex.membres - WHERE uid={?} AND asso_id={?}", Session::getInt('uid'), $globals->asso('id')); + WHERE uid={?} AND asso_id={?}", S::v('uid'), $globals->asso('id')); return $res->fetchOneCell() == 'admin'; } @@ -167,13 +142,13 @@ function is_member() { if (!$asso_id) { return false; } static $is_member; if (!$is_member) $is_member = array(); - if (!isset($is_member[$asso_id])) + if (!isset($is_member[$asso_id])) { - $res = $globals->xdb->query( + $res = XDB::query( "SELECT COUNT(*) FROM groupex.membres WHERE uid={?} AND asso_id={?}", - Session::getInt('uid'), $asso_id); + S::v('uid'), $asso_id); $is_member[$asso_id] = $res->fetchOneCell() == 1; } return $is_member[$asso_id];