Mise à jour de l'authentification

This commit is contained in:
Michael RICOIS 2011-08-30 12:08:07 +00:00
parent 6d90e076c2
commit bd01d28c31
2 changed files with 25 additions and 6 deletions

View File

@ -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,6 +26,7 @@ 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);
$result = $auth->authenticate($authAdapter);
@ -34,14 +36,29 @@ class UserController extends Zend_Controller_Action {
$this->view->message.= $message."<br/>";
}
} else {
if (Zend_Registry::isRegistered('URL')){
$url = Zend_Registry::get('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('/');
}
}
}
}

View File

@ -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__);