Admin et Gestion

This commit is contained in:
Michael RICOIS 2012-05-16 14:28:32 +00:00
parent 23bcadcf02
commit ff681eaa64

View File

@ -11,31 +11,31 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
{
$checkAuth = true;
if ($request->getControllerName()=='user' && $request->getActionName()=='login'){
$checkAuth = false;
$checkAuth = false;
}
if ($checkAuth)
if ($checkAuth)
{
$login = $request->getParam('login');
$pass = $request->getParam('pass', '');
$hach = $request->getParam('hach');
$checkIp = $request->getParam('checkIp');
$auth = Zend_Auth::getInstance();
//Est ce que l'on a checkIp=only lors de la requête
$iponly = false;
if ($checkIp=='only') {
if ($checkIp=='only') {
$hach = 'iponly:'.$_SERVER['REMOTE_ADDR'];
$iponly = true;
$iponly = true;
}
//On vérifie le tout lors d'une connexion par url
if ( !empty($login) && !empty($hach) ) {
$authAdapter = new Scores_AuthAdapter($login, $hach, $iponly);
$result = $auth->authenticate($authAdapter);
if (!$result->isValid()) {
$messageF = '';
foreach ($result->getMessages() as $message) {
@ -45,43 +45,49 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
->setControllerName('user')
->setActionName('logout')
->setParam('message', $messageF);
} else {
} else {
$storage = new Zend_Auth_Storage_Session();
$session = new Zend_Session_Namespace($storage->getNamespace());
//$session->setExpirationSeconds(86400);
$auth->setStorage($storage);
}
//Sinon on reste sur le standard
} else {
//Pas authentifié
if ( !$auth->hasIdentity() || time() > $auth->getIdentity()->time ) {
$auth->clearIdentity();
$session = new Zend_Session_Namespace('login');
$session->url = $_SERVER['REQUEST_URI'];
$layout = Zend_Layout::getMVCInstance();
if ( !$layout->isEnabled() ) {
if ( !$layout->isEnabled() ) {
echo "Identification incorrect ou périmé.";
} else {
$this->_response->setRedirect('/user/login')->sendResponse();
}
//Authentifié => on met à jour la session
} else {
$identity = $auth->getIdentity();
$identity = $auth->getIdentity();
$identity->time = time() + $identity->timeout;
$auth->getStorage()->write($identity);
if ( $identity->profil=="SuperAdministrateur" ) {
$layout = Zend_Layout::getMVCInstance();
$view = $layout->getView();
$view->admin = true;
}
if (Zend_Session::namespaceIsset('login')){
Zend_Session::namespaceUnset('login');
}
}
}
}
}
}
}