Autorisé les connexions de tous les utilisateurs actifs

This commit is contained in:
Michael RICOIS 2015-06-11 13:00:33 +00:00
parent 43990a22fc
commit 33927fc6dc

View File

@ -11,22 +11,28 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
{
$controller = $request->getControllerName();
$action = $request->getActionName();
$checkAuth = true;
// --- Pas d'authentification sur la demande d'authentification
if ( $controller == 'user' && in_array($action, array('login', 'logout')) ) {
$checkAuth = false;
}
if ($checkAuth) {
$login = $request->getParam('login');
$pass = $request->getParam('pass', '');
$hach = $request->getParam('hach');
if (!empty($hach)) {
$pass = $hach;
}
$checkIp = $request->getParam('checkIp');
// --- Est ce que l'on a checkIp=only lors de la requête
$iponly = false;
if ($checkIp == 'only') {
$hach = 'iponly:'.$_SERVER['REMOTE_ADDR'];
$iponly = true;
}
$auth = Zend_Auth::getInstance();
@ -37,11 +43,10 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
$result = $auth->authenticate($authAdapter);
if ( $result->isValid() ) {
$storage = new Zend_Auth_Storage_Session();
$session = new Zend_Session_Namespace($storage->getNamespace());
//$session->setExpirationSeconds(86400);
$auth->setStorage($storage);
$storage = new Zend_Auth_Storage_Session();
$session = new Zend_Session_Namespace($storage->getNamespace());
$auth->setStorage($storage);
} else {
@ -49,7 +54,7 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
foreach ($result->getMessages() as $message) {
$messageDisplay.= $message."<br/>";
}
$layout = Zend_Layout::getMVCInstance();
if ( $layout->isEnabled() ){
$request->setModuleName('default')
@ -69,23 +74,23 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
// --- Authentifié
if ( $auth->hasIdentity() ) {
// --- Mise à jour du délai de connexion
if ( time() < $auth->getIdentity()->time ) {
$identity = $auth->getIdentity();
$identity->time = time() + $identity->timeout;
// --- Vérification des paramètres du contrat
if ( $identity->dateContrat === null && $layout->isEnabled() ) {
// --- Get customer's params
$paramsM = new Application_Model_CiblageCustomerParams();
$sql = $paramsM->select()
->where('idClient = ?', $identity->idClient)
//@todo : add service from WebService
->order('dateContrat DESC')->limit(1);
$params = $paramsM->fetchRow($sql);
if ( $params !== null ) {
$identity->filterRNCS = $params->filterRNCS;
@ -98,80 +103,52 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
$identity->priceLine = $params->priceLine;
$identity->forfait = $params->forfait;
}
// --- Get user's preference
$prefsM = new Application_Model_CiblagePrefs();
$pref = $prefsM->find($identity->username)->current();
if ( $pref !== null ) {
$identity->preferences = json_decode($pref->json);
}
// --- Add a global value to join filterRNCS and preferences RNCS
if ( $identity->filterRNCS ) {
$identity->globalRNCS = 1;
}
if ( isset($identity->preferences->filter->rncs)
&& $identity->preferences->filter->rncs ==1 ) {
$identity->globalRNCS = 1;
}
}
// --- No contrat define
if ( $identity->dateContrat == '0000-00-00 00:00:00' || $identity->dateContrat === null ) {
// --- If no params are detected, display a message to contact support
$request->setModuleName('default')
->setControllerName('aide')
->setActionName('message')
->setParam('typeMsg', 'support');
}
// --- Check dateContrat and calculate end of contrat
else {
$hour = intval(substr($identity->dateContrat,11,2));
$min = intval(substr($identity->dateContrat,14,2));
$sec = intval(substr($identity->dateContrat,17,2));
$month = intval(substr($identity->dateContrat,5,2)) + $identity->periodContrat;
$day = intval(substr($identity->dateContrat,8,2));
$year = intval(substr($identity->dateContrat,0,4));
$dateFinContrat = mktime($hour,$min,$sec,$month,$day,$year);
if ( time() > $dateFinContrat ) {
$request->setModuleName('default')
->setControllerName('user')
->setActionName('logout')
->setParam('message', "Votre Contrat est arrivé à expiration.");
}
}
// --- Sauvegarde des paramètres
$auth->getStorage()->write($identity);
// --- Activation profil SuperAdministrateur
if ( $identity->profil == "SuperAdministrateur" ) {
$view = $layout->getView();
$view->admin = true;
}
if (Zend_Session::namespaceIsset('login')){
Zend_Session::namespaceUnset('login');
}
}
// --- Temps de connexion dépassé
elseif ( time() > $auth->getIdentity()->time ) {
$auth->clearIdentity();
$storage = $auth->getStorage();
Zend_Session::namespaceUnset($storage->getNamespace());
if ( !$request->isXmlHttpRequest() ) {
$session = new Zend_Session_Namespace('login');
$session->url = $_SERVER['REQUEST_URI'];
}
if ( $request->getControllerName()=='index' && $request->getActionName()=='index' ) {
$request->setModuleName('default')
->setControllerName('user')
@ -182,13 +159,13 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
->setActionName('logout')
->setParam('ajax', $request->isXmlHttpRequest());
}
}
}
// --- Pas Authentifié
else {
if ( $request->isXmlHttpRequest() ) {
$request->setModuleName('default')
@ -206,7 +183,7 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
->setActionName('login');
}
}
}
}