62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
|
class UserController extends Zend_Controller_Action
|
|
{
|
|
public function init()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
}
|
|
|
|
public function loginAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$this->view->headLink()
|
|
->appendStylesheet('/themes/default/css/signin.css', 'all');
|
|
|
|
$this->view->headTitle()->append('Connexion');
|
|
|
|
$form = new Application_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 Scores_Auth_Adapter_Db($login, $pass);
|
|
|
|
$result = $auth->authenticate($authAdapter);
|
|
|
|
if ( $result->isValid() ) {
|
|
//$timeout = $auth->getIdentity()->timeout;
|
|
$timeout = 86400;
|
|
|
|
//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);
|
|
|
|
$this->redirect('/');
|
|
} else {
|
|
$this->view->message = '';
|
|
foreach ($result->getMessages() as $message) {
|
|
$this->view->message.= $message."<br/>";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function logoutAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
Zend_Auth::getInstance()->clearIdentity();
|
|
}
|
|
} |