From bd01d28c318f1d9e1908702b7ad3d142a11704b3 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Tue, 30 Aug 2011 12:08:07 +0000 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20l'authentification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/UserController.php | 29 +++++++++++++++++----- library/Web/WebAuthAdapter.php | 2 ++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/application/controllers/UserController.php b/application/controllers/UserController.php index cffe7219..80b446fd 100644 --- a/application/controllers/UserController.php +++ b/application/controllers/UserController.php @@ -17,6 +17,7 @@ class UserController extends Zend_Controller_Action { public function loginAction() { + $this->view->headTitle()->append('Connexion'); $form = new Form_Login(); $this->view->form = $form; $request = $this->getRequest(); @@ -25,8 +26,9 @@ class UserController extends Zend_Controller_Action { if ($form->isValid($formData)) { $login = $form->getValue('login'); $pass = $form->getValue('pass'); + $auth = Zend_Auth::getInstance(); - $authAdapter = new WebAuthAdapter($login, $pass); + $authAdapter = new WebAuthAdapter($login, $pass); $result = $auth->authenticate($authAdapter); if (!$result->isValid()){ $this->view->message = ''; @@ -34,14 +36,29 @@ class UserController extends Zend_Controller_Action { $this->view->message.= $message."
"; } } else { - if (Zend_Registry::isRegistered('URL')){ - $url = Zend_Registry::get('URL'); - if (!empty($url)){ - $this->_redirect($url); - } + $timeout = $auth->getIdentity()->timeout; + + //Ecrit un cookie persistant valide pendant le temps definit + Zend_Session::rememberMe($timeout); + + $storage = new Zend_Auth_Storage_Session(); + $sessionNamespace = new Zend_Session_Namespace($storage->getNamespace()); + $sessionNamespace->setExpirationSeconds($timeout); + $auth->setStorage($storage); + $url = ''; + if (Zend_Session::namespaceIsset('login')){ + $session = new Zend_Session_Namespace('login'); + if (isset($session->url)) { + $url = $session->url; + } + } + if (!empty($url)){ + $this->_redirect($url); } + $this->_redirect('/'); } + } } } diff --git a/library/Web/WebAuthAdapter.php b/library/Web/WebAuthAdapter.php index 3adaefd4..30132ac0 100644 --- a/library/Web/WebAuthAdapter.php +++ b/library/Web/WebAuthAdapter.php @@ -7,6 +7,7 @@ class WebAuthAdapter implements Zend_Auth_Adapter_Interface protected $_username; protected $_password; protected $_hash; + protected $_timeout = 1800; public function __construct($username,$password) { @@ -36,6 +37,7 @@ class WebAuthAdapter implements Zend_Auth_Adapter_Interface $identity->username = $this->_username; $identity->hash = $this->_hash; $identity->idClient = $tabRep['idClient']; + $identity->timeout = (!empty($tabRep['timeout'])) ? $tabRep['timeout'] : $this->_timeout; if (count($rep)==0){ //debugLog('W',"CheckAuth $login/$password inexistant ou inactif (IP=$ipConnexion)", __LINE__,__FILE__, __FUNCTION__, __CLASS__);