extranet/application/controllers/UserController.php
2011-04-18 14:36:06 +00:00

126 lines
3.6 KiB
PHP

<?php
require_once 'Web/Forms/Login.php';
require_once 'Web/WebAuthAdapter.php';
class UserController extends Zend_Controller_Action {
public function init()
{
}
public function indexAction()
{
$this->view->headLink()->appendStylesheet('/themes/default/styles/form.css', 'all');
require_once 'Scores/WsScores.php';
$ws = new WsScores();
//Liste de tous les droits
$listeDroits = $ws->getListeDroits();
$droitsLib = array();
foreach($listeDroits->item as $droit) {
$droitsLib[$droit->code] = $droit->desc;
}
$this->view->assign('droitsLib', $droitsLib);
//Liste de toutes les préférences
$listePrefs = $ws->getListePrefs();
$prefsLib = array();
foreach($listePrefs->item as $pref) {
$prefsLib[$pref->code] = $pref->desc;
}
$this->view->assign('prefsLib', $prefsLib);
$auth = Zend_Auth::getInstance();
$identity = $auth->getIdentity();
$isAdmin = false;
if ($identity->profil == 'Administrateur'
|| $identity->profil == 'SuperAdministrateur') {
$isAdmin = true;
}
$this->view->assign('options', $identity);
$this->view->assign('isAdmin', $isAdmin);
$this->view->assign('loginVu', $identity->username);
if (!isset($_REQUEST['action']) || $_REQUEST['action']!='new') {
$this->view->assign('loginNew', '');
$this->view->assign('droits', explode(' ', $identity->droits));
$this->view->assign('droitsClients', explode(' ', $identity->droitsClients));
$this->view->assign('action', 'edit');
$this->view->assign('pref', explode(' ',$identity->pref));
} else {
$reponse = $ws->getNextLogin($loginVu);
$this->view->assign('loginNew', $reponse->result->racine);
$this->view->assign('droitsClients', explode(' ', $reponse->result->droitsClients));
$this->view->assign('action', 'new');
$this->view->assign('pref', array());
}
}
public function saveAction()
{
}
public function changepwdAction()
{
}
public function loginAction()
{
//@todo : gestion des affichages particuliers pour les clients
$activeNav = $this->view->navigation();
$activeNav->removePages();
$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;
$storage = new Zend_Auth_Storage_Session();
$sessionNamespace = new Zend_Session_Namespace($storage->getNamespace());
$sessionNamespace->setExpirationSeconds($timeout);
$auth->setStorage($storage);
$url = '';
if (Zend_Registry::isRegistered('URL')){
$url = Zend_Registry::get('URL');
}
if (!empty($url)){
$this->_redirect($url);
}
$this->_redirect('/');
}
}
}
$this->_helper->layout()->disableLayout();
$this->render('login');
}
public function logoutAction()
{
$activeNav = $this->view->navigation();
$activeNav->removePages();
Zend_Auth::getInstance()->clearIdentity();
$this->_helper->layout()->disableLayout();
$this->render('logout');
}
}