diff --git a/application/modules/admin/controllers/AuthController.php b/application/modules/admin/controllers/AuthController.php index 56b9ead0c13fc5aaccb0e08587f6995b1993a50a..e66cb4271f243d3e1cca8923a027f415fbbaa70c 100644 --- a/application/modules/admin/controllers/AuthController.php +++ b/application/modules/admin/controllers/AuthController.php @@ -45,49 +45,24 @@ class Admin_AuthController extends Zend_Controller_Action //---------------------------------------------------------------------------------- // Formulaire d'identification //---------------------------------------------------------------------------------- - function loginAction() - { + function loginAction() { $this->view->message = ''; - if ($this->_request->isPost()) - { - // Champs de saisie - $f = new Zend_Filter_StripTags(); - $username = $f->filter($this->_request->getPost('username')); - $password = $f->filter($this->_request->getPost('password')); + if (!$this->_request->isPost()) + return; - if (empty($username)) $this->view->message = "Entrez votre nom d'utilisateur puis validez S.V.P."; - else - { - // setup Zend_/Auth adapter for a database table - $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter()); - $authAdapter->setTableName('bib_admin_users'); - $authAdapter->setIdentityColumn('LOGIN'); - $authAdapter->setCredentialColumn('PASSWORD'); - // Set the input credential values to authenticate against - $authAdapter->setIdentity($username); - $authAdapter->setCredential($password); + // Champs de saisie + $f = new Zend_Filter_StripTags(); + $username = $f->filter($this->_request->getPost('username')); + $password = $f->filter($this->_request->getPost('password')); - // do the authentication - $auth = ZendAfi_Auth::getInstance(); - try - { - $result = $auth->authenticate($authAdapter); - - // success: store database row to auth's storage (sauf le password) - if ($result->isValid()) - { - $data = $authAdapter->getResultRowObject(null,'password'); - $auth->getStorage()->write($data); - if($auth->hasIdentity()) $this->_redirect('admin/'); - } - } - catch (Exception $e) - { - logErrorMessage('Class: Admin_AuthController; Function: loginAction' . NL . $e->getMessage()); - $this->_redirect('admin/error/database'); - } - } + if (empty($username)) { + $this->view->message = "Entrez votre nom d'utilisateur puis validez S.V.P."; + return; } + + $auth = ZendAfi_Auth::getInstance(); + if ($auth->authenticateLoginPassword($username, $password, [$auth->newAuthDb()])) + $this->_redirect('admin/'); } //---------------------------------------------------------------------------------- diff --git a/application/modules/opac/controllers/AuthController.php b/application/modules/opac/controllers/AuthController.php index ab3ac517a816b803650c16ecf879d2604df31329..8048cd4a144a58edd573a2bd690a469432bce6a1 100644 --- a/application/modules/opac/controllers/AuthController.php +++ b/application/modules/opac/controllers/AuthController.php @@ -51,15 +51,8 @@ class AuthController extends Zend_Controller_Action return $this->view->_('Entrez votre mot de passe S.V.P.'); // do the authentication - $auth = ZendAfi_Auth::getInstance(); - - foreach ($auth->getOrderedAdaptersForLoginPassword($username, $password) as $authAdapter) { - if (!$auth->authenticate($authAdapter)->isValid()) continue; - $auth->getStorage()->write($authAdapter->getResultObject()); - return null; - } - - return $this->view->_('Identifiant ou mot de passe incorrect.'); + if (!ZendAfi_Auth::getInstance()->authenticateLoginPassword($username, $password)) + return $this->view->_('Identifiant ou mot de passe incorrect.'); } //------------------------------------------------------------------------------------------------------ diff --git a/library/ZendAfi/Auth.php b/library/ZendAfi/Auth.php index 29c3ef1dbf0d208923dcea070385b0afcc55fb14..f58a6383740387542ff8b59b53cfcea8d156058d 100644 --- a/library/ZendAfi/Auth.php +++ b/library/ZendAfi/Auth.php @@ -35,13 +35,7 @@ class ZendAfi_Auth extends Zend_Auth { public function getOrderedAdaptersForLoginPassword($login, $password) { - $adapters = [ $this->newAuthDb(), - $this->newAuthSIGB() ]; - foreach ($adapters as $adapter) { - $adapter->setIdentity($login); - $adapter->setCredential($password); - } - return $adapters; + return [ $this->newAuthDb(), $this->newAuthSIGB() ]; } @@ -57,6 +51,22 @@ class ZendAfi_Auth extends Zend_Auth { public function newAuthSIGB() { return new ZendAfi_Auth_Adapter_CommSigb(); } + + + public function authenticateLoginPassword($login, $password, $adapters = null) { + if (!$adapters) + $adapters = $this->getOrderedAdaptersForLoginPassword($login, $password); + + foreach ($adapters as $authAdapter) { + $authAdapter->setIdentity($login); + $authAdapter->setCredential($password); + + if (!$this->authenticate($authAdapter)->isValid()) continue; + $this->getStorage()->write($authAdapter->getResultObject()); + return true; + } + return false; + } } ?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/AdminAuth.php b/library/ZendAfi/Controller/Plugin/AdminAuth.php index b5bdccd45fd7f868ed86a006634765aa90c448b4..ffcfdd45103b634e272253dc7dd942be69482a8f 100644 --- a/library/ZendAfi/Controller/Plugin/AdminAuth.php +++ b/library/ZendAfi/Controller/Plugin/AdminAuth.php @@ -33,7 +33,7 @@ class ZendAfi_Controller_Plugin_AdminAuth extends Zend_Controller_Plugin_Abstrac $action = $this->_request->getActionName(); $session = Zend_Registry::get('session'); - $auth = Zend_Auth::getInstance(); + $auth = ZendAfi_Auth::getInstance(); if (isset($session->baseUrl)) { diff --git a/tests/library/Class/Systeme/ModulesMenuTest.php b/tests/library/Class/Systeme/ModulesMenuTest.php index f33929b2e189500f985ca2b19018fb1474b97c05..6f4b19c07d5f1e9e0c4ce684fa31978c83759c03 100644 --- a/tests/library/Class/Systeme/ModulesMenuTest.php +++ b/tests/library/Class/Systeme/ModulesMenuTest.php @@ -50,7 +50,7 @@ class ModulesMenuTest extends Storm_Test_ModelTestCase { /** @test */ public function vodeclicUrlWithoutUserShouldBeLoginPage() { - Zend_Auth::getInstance()->clearIdentity(); + ZendAfi_Auth::getInstance()->clearIdentity(); $this->assertEquals(array('url' => BASE_URL.'/auth/login', 'target' => '0'), $this->module_menu->getUrl('VODECLIC', array())); } @@ -62,7 +62,7 @@ class ModulesMenuTest extends Storm_Test_ModelTestCase { $account->password = 'password'; $account->ID_USER = 34; - Zend_Auth::getInstance()->getStorage()->write($account); + ZendAfi_Auth::getInstance()->getStorage()->write($account); return Class_Users::getLoader() ->newInstanceWithId(34) diff --git a/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php b/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php index beb7d07ee670cc9ff7acdf3a1cf0ccdd4ced9c82..c951925a326cdd197cf1974f91ba46734fe96d9b 100644 --- a/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php +++ b/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php @@ -123,7 +123,7 @@ abstract class ViewHelperTestCase extends PHPUnit_Framework_TestCase { public function logout() { - Zend_Auth::getInstance()->clearIdentity(); + ZendAfi_Auth::getInstance()->clearIdentity(); } public function login($role) { @@ -144,7 +144,7 @@ abstract class ViewHelperTestCase extends PHPUnit_Framework_TestCase { ->newInstanceWithId(1) ->setLibelle('Tombouctou'); - Zend_Auth::getInstance()->getStorage()->write($account); + ZendAfi_Auth::getInstance()->getStorage()->write($account); } } ?> \ No newline at end of file