webservice/application/controllers/UserController.php
2011-08-30 12:08:07 +00:00

71 lines
1.8 KiB
PHP

<?php
require_once 'Web/forms/login.php';
require_once 'Web/WebAuthAdapter.php';
class UserController extends Zend_Controller_Action {
public function init()
{
$activeNav = $this->view->navigation();
$activeNav->removePages();
}
public function indexAction()
{
}
public function loginAction()
{
$this->view->headTitle()->append('Connexion');
$form = new Form_Login();
$this->view->form = $form;
$request = $this->getRequest();
if ($request->isPost()) {
$formData = $request->getPost ();
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);
if (!$result->isValid()){
$this->view->message = '';
foreach ($result->getMessages() as $message) {
$this->view->message.= $message."<br/>";
}
} else {
$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('/');
}
}
}
}
public function logoutAction()
{
Zend_Auth::getInstance()->clearIdentity();
}
}