91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
<?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)
|
|
{
|
|
$checkAuth = true;
|
|
//Pas d'authentification sur la demande d'authentification
|
|
if ($request->getControllerName()=='user' && $request->getActionName()=='login'){
|
|
$checkAuth = false;
|
|
}
|
|
|
|
// Pas d'authentification sur ces services
|
|
if (in_array($request->getControllerName(), array('service', 'import')) ) {
|
|
$checkAuth = false;
|
|
}
|
|
|
|
$checkWs = true;
|
|
if ( $request->getControllerName()=='fichier' ) {
|
|
$checkWs = false;
|
|
}
|
|
|
|
if ($checkAuth) {
|
|
$login = $request->getParam('login');
|
|
$pass = $request->getParam('pass', '');
|
|
$hach = $request->getParam('hach');
|
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
//On vérifie le tout lors d'une connexion par url
|
|
if ( !empty($login) && !empty($hach) ) {
|
|
|
|
require_once 'Web/WebAuthAdapter.php';
|
|
$authAdapter = new WebAuthAdapter($login, $hach, $checkWs);
|
|
$result = $auth->authenticate($authAdapter);
|
|
if (!$result->isValid()) {
|
|
$layout = Zend_Layout::getMVCInstance();
|
|
if ( !$layout->isEnabled() ){
|
|
echo "Identification incorrect ou périmé.";
|
|
} else {
|
|
$request->setModuleName('default')
|
|
->setControllerName('user')
|
|
->setActionName('logout');
|
|
}
|
|
} else {
|
|
$timeout = $auth->getIdentity()->timeout;
|
|
Zend_Session::rememberMe($timeout);
|
|
$storage = new Zend_Auth_Storage_Session();
|
|
$sessionNamespace = new Zend_Session_Namespace($storage->getNamespace());
|
|
$sessionNamespace->setExpirationSeconds($timeout);
|
|
$auth->setStorage($storage);
|
|
}
|
|
|
|
//Sinon on reste sur le standard
|
|
} else {
|
|
//Pas authentifié
|
|
if (!$auth->hasIdentity()) {
|
|
|
|
$auth->clearIdentity();
|
|
$session = new Zend_Session_Namespace('login');
|
|
$session->url = $_SERVER['REQUEST_URI'];
|
|
|
|
$layout = Zend_Layout::getMVCInstance();
|
|
if (!$layout->isEnabled()){
|
|
echo "Identification incorrect ou périmé.";
|
|
} else {
|
|
$this->_response->setRedirect('/user/login')->sendResponse();
|
|
}
|
|
//Authentifié => on met à jour la session
|
|
} else {
|
|
|
|
$timeout = $auth->getIdentity()->timeout;
|
|
$storage = new Zend_Auth_Storage_Session();
|
|
$sessionNamespace = new Zend_Session_Namespace($storage->getNamespace());
|
|
$sessionNamespace->setExpirationSeconds($timeout);
|
|
$auth->setStorage($storage);
|
|
|
|
if (Zend_Session::namespaceIsset('login')){
|
|
Zend_Session::namespaceUnset('login');
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |