2011-10-24 17:05:30 +02:00
|
|
|
<?php
|
|
|
|
class UserController extends Zend_Controller_Action
|
|
|
|
{
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
require_once 'Forms/Login.php';
|
|
|
|
require_once 'Scores/WebAuthAdapter.php';
|
|
|
|
require_once 'Scores/WsScores.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gestion de l'authentification
|
|
|
|
*/
|
|
|
|
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, md5($login.'|'.$pass));
|
|
|
|
$result = $auth->authenticate($authAdapter);
|
|
|
|
if (!$result->isValid()){
|
|
|
|
$this->view->message = '';
|
|
|
|
Zend_Registry::get('firebug')->info($result);
|
|
|
|
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) && $url!='/user/login' && $url!='/localauth'){
|
|
|
|
$this->_redirect($url);
|
|
|
|
}
|
|
|
|
$this->_redirect('/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$this->render('login');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gestion de la déconnexion
|
|
|
|
*/
|
|
|
|
public function logoutAction()
|
|
|
|
{
|
2012-01-03 11:44:45 +01:00
|
|
|
//Suppression des critères de comptage en session
|
|
|
|
require_once 'Scores/SessionCiblage.php';
|
|
|
|
$session = new SessionCiblage();
|
|
|
|
$session->clearCiblage();
|
|
|
|
|
|
|
|
//Suppression de l'identité
|
2011-10-24 17:05:30 +02:00
|
|
|
Zend_Auth::getInstance()->clearIdentity();
|
2012-01-03 11:44:45 +01:00
|
|
|
|
2011-10-24 17:05:30 +02:00
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
|
|
|
|
$url = 'http://www.scores-decisions.com/';
|
|
|
|
$refresh = 5;
|
|
|
|
|
|
|
|
if (APPLICATION_ENV != 'production'){
|
|
|
|
$url = 'http://'.$_SERVER['SERVER_NAME'].$this->view->url(array(
|
|
|
|
'controller' => 'user',
|
|
|
|
'action' => 'login',
|
|
|
|
));
|
|
|
|
}
|
2012-01-04 12:29:07 +01:00
|
|
|
|
2011-10-24 17:05:30 +02:00
|
|
|
$this->view->assign('url', $url);
|
|
|
|
$this->view->headMeta()->appendHttpEquiv('refresh', '5; url='.$url);
|
|
|
|
$this->render('logout');
|
|
|
|
}
|
|
|
|
}
|