2011-01-11 08:43:13 +00:00
|
|
|
<?php
|
|
|
|
class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Vérifie les autorisations
|
|
|
|
* Utilise _request et _response hérités et injectés par le FC
|
|
|
|
*
|
|
|
|
* @param Zend_Controller_Request_Abstract $request : non utilisé, mais demandé par l'héritage
|
|
|
|
*/
|
|
|
|
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
|
|
|
{
|
2011-04-27 12:09:12 +00:00
|
|
|
if ($request->getControllerName()!='user' && $request->getActionName()!='login')
|
2011-01-11 08:43:13 +00:00
|
|
|
{
|
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
//Pas authentifié
|
2011-05-18 07:44:43 +00:00
|
|
|
if (!$auth->hasIdentity()) {
|
|
|
|
|
|
|
|
$auth->clearIdentity();
|
|
|
|
$session = new Zend_Session_Namespace('login');
|
|
|
|
$session->url = $_SERVER['REQUEST_URI'];
|
2011-01-11 08:43:13 +00:00
|
|
|
$this->_response->setRedirect('/user/login');
|
2011-05-18 07:44:43 +00:00
|
|
|
|
|
|
|
//Authentifié => on met à jour la session
|
2011-01-11 08:43:13 +00:00
|
|
|
} else {
|
2011-05-18 07:44:43 +00:00
|
|
|
|
2011-01-11 08:43:13 +00:00
|
|
|
$timeout = $auth->getIdentity()->timeout;
|
|
|
|
$storage = new Zend_Auth_Storage_Session();
|
|
|
|
$sessionNamespace = new Zend_Session_Namespace($storage->getNamespace());
|
|
|
|
$sessionNamespace->setExpirationSeconds($timeout);
|
|
|
|
$auth->setStorage($storage);
|
2011-05-18 07:44:43 +00:00
|
|
|
|
|
|
|
if (Zend_Session::namespaceIsset('login')){
|
|
|
|
Zend_Session::namespaceUnset('login');
|
|
|
|
}
|
|
|
|
|
2011-01-11 08:43:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|