154 lines
4.5 KiB
PHP
154 lines
4.5 KiB
PHP
<?php
|
|
class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
|
{
|
|
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
|
{
|
|
$checkAuth = true;
|
|
if ($request->getControllerName()=='user' && $request->getActionName()=='login') {
|
|
$checkAuth = false;
|
|
}
|
|
|
|
if ($request->getControllerName()=='user' && $request->getActionName()=='motpasse') {
|
|
$checkAuth = false;
|
|
}
|
|
|
|
if ($request->getControllerName()=='auth') {
|
|
$checkAuth = false;
|
|
}
|
|
|
|
if ($request->getModuleName()=='file' && $request->getClientIp(false)=='78.31.45.206') {
|
|
$checkAuth = false;
|
|
}
|
|
|
|
if ($checkAuth) {
|
|
|
|
$login = $request->getParam('login');
|
|
$pass = $request->getParam('pass', '');
|
|
$hach = $request->getParam('hach');
|
|
$checkIp = $request->getParam('checkIp');
|
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
$mode = null;
|
|
// --- Mode checkIp=only
|
|
if ($checkIp == 'only') {
|
|
$hach = 'iponly:'.$_SERVER['REMOTE_ADDR'];
|
|
$mode = 'iponly';
|
|
}
|
|
|
|
// --- On vérifie le tout lors d'une connexion par url
|
|
if ( !empty($login) && !empty($hach) ) {
|
|
|
|
// --- Mode hach
|
|
if ($mode === null) {
|
|
$mode = 'hach';
|
|
}
|
|
|
|
$authAdapter = new Scores_Auth_Adapter_Ws($login, $hach, $mode);
|
|
$result = $auth->authenticate($authAdapter);
|
|
|
|
if ( $result->isValid() ) {
|
|
|
|
// --- Store identity in sesssion
|
|
$storage = new Zend_Auth_Storage_Session();
|
|
$session = new Zend_Session_Namespace($storage->getNamespace());
|
|
$auth->setStorage($storage);
|
|
|
|
$user = new Scores_Utilisateur();
|
|
$info = get_browser();
|
|
if ( $info ) {
|
|
$isMobile = ($info->ismobiledevice==1) ? 1 : 0;
|
|
$user->setBrowserInfo($info->platform, $info->browser, $info->version, $isMobile);
|
|
} else {
|
|
//Save botnet information
|
|
}
|
|
|
|
} else {
|
|
$messageF = '';
|
|
foreach ($result->getMessages() as $message) {
|
|
$messageF.= $message."<br/>";
|
|
}
|
|
$request->setModuleName('default')
|
|
->setControllerName('user')
|
|
->setActionName('logout')
|
|
->setParam('message', $messageF);
|
|
}
|
|
|
|
// --- Sinon on reste sur le standard
|
|
} else {
|
|
|
|
// --- Authentifié
|
|
if ( $auth->hasIdentity() ) {
|
|
|
|
// --- Mise à jour du délai de connexion
|
|
if ( time() < $auth->getIdentity()->time ) {
|
|
|
|
$identity = $auth->getIdentity();
|
|
$identity->time = time() + $identity->timeout;
|
|
$auth->getStorage()->write($identity);
|
|
|
|
if (Zend_Session::namespaceIsset('login')){
|
|
Zend_Session::namespaceUnset('login');
|
|
}
|
|
|
|
// --- Check CGU
|
|
if ( $request->getControllerName()!='aide' && $request->getActionName()!='cgu'
|
|
|| $request->getControllerName()!='user' && $request->getActionName()!='logout') {
|
|
if ( empty($identity->acceptationCGU) || $identity->acceptationCGU=='0000-00-00 00:00:00' ) {
|
|
$request->setModuleName('default')
|
|
->setControllerName('aide')
|
|
->setActionName('cgu');
|
|
}
|
|
}
|
|
|
|
// --- 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')
|
|
->setActionName('login');
|
|
} else {
|
|
$request->setModuleName('default')
|
|
->setControllerName('user')
|
|
->setActionName('logout')
|
|
->setParam('ajax', $request->isXmlHttpRequest());
|
|
}
|
|
}
|
|
|
|
}
|
|
// --- Pas Authentifié
|
|
else {
|
|
|
|
if ( $request->isXmlHttpRequest() ) {
|
|
|
|
$request->setModuleName('default')
|
|
->setControllerName('user')
|
|
->setActionName('logout')
|
|
->setParam('ajax', 1);
|
|
|
|
} else {
|
|
|
|
$session = new Zend_Session_Namespace('login');
|
|
$session->url = $_SERVER['REQUEST_URI'];
|
|
|
|
$request->setModuleName('default')
|
|
->setControllerName('user')
|
|
->setActionName('login');
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |