X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2FPlatal.php;h=88e06501699d70d847b83438c57e45b957ef8653;hb=3aec1c213ff4bc67300f938dde79a10b44285f31;hp=46d0d4d192fecfdc94770ff8d797a859179de02f;hpb=c9178c75cab8a35b0aa4b4000708569f9f3359c4;p=platal.git diff --git a/classes/Platal.php b/classes/Platal.php index 46d0d4d..88e0650 100644 --- a/classes/Platal.php +++ b/classes/Platal.php @@ -19,8 +19,6 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -define('PL_OK', 0); -define('PL_NEEDLOGIN', 1); define('PL_FORBIDDEN', 403); define('PL_NOT_FOUND', 404); @@ -43,14 +41,23 @@ class Platal array_unshift($modules, 'core'); foreach ($modules as $module) { - $this->__mods[$module] = $m = PLModule::factory($this, $module); + $this->__mods[$module] = $m = PLModule::factory($module); $this->__hooks += $m->handlers(); } } - function set_index_module($mod) + function pl_self($n = null) { - $this->__idx = $mod; + if (is_null($n)) + return $this->path; + + if ($n >= 0) + return join('/', array_slice($this->argv, 0, $n + 1)); + + if ($n <= -count($this->argv)) + return $this->argv[0]; + + return join('/', array_slice($this->argv, 0, $n)); } function find_hook() @@ -91,18 +98,33 @@ class Platal $args = $this->argv; $args[0] = &$page; - if ($hook['auth'] > Session::get('auth', AUTH_PUBLIC)) { - $_SESSION['session']->doAuth($page); + if ($hook['auth'] > S::v('auth', AUTH_PUBLIC)) { + // FIXME: don't use 'session' object anymore + if (!$_SESSION['session']->doAuth()) { + $this->force_login($page); + } } return call_user_func_array($hook['hook'], $args); } + function force_login(&$page) + { + if (S::logged() and !$new_name) { + $page->changeTpl('password_prompt_logged.tpl'); + $page->addJsLink('javascript/do_challenge_response_logged.js'); + } else { + $page->changeTpl('password_prompt.tpl'); + $page->addJsLink('javascript/do_challenge_response.js'); + } + $page->run(); + } + function run() { global $page; - new_skinned_page('index.tpl', AUTH_PUBLIC); + new_skinned_page('index.tpl'); if (empty($this->path)) { $this->path = 'index';