webservice/application/controllers/UserController.php

131 lines
4.5 KiB
PHP

<?php
class UserController extends Zend_Controller_Action
{
public function indexAction()
{
}
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, true);
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
$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);
$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();
}
public function paramsAction()
{
$auth = Zend_Auth::getInstance();
$identity = $auth->getIdentity();
$login = $identity->username;
$pass = $identity->hash;
$this->view->login = $login;
$this->view->authorizationHeader = base64_encode($login.':'.$pass);
$userM = new Application_Model_Sdv1Utilisateurs();
$sql = $userM->select()->where('id=?', $identity->id);
$user = $userM->fetchRow($sql);
$this->view->IdFullName = $user->civilite . ' ' . $user->nom . ' ' . $user->prenom;
$this->view->IdEmail = $user->email;
//Liste des droits
$listdroit = explode(' ', $user->droits);
//Association méthodes - droits
$assoc = array(
'getAnnoncesAsso' => array('ANNONCES'),
'getAnnoncesBalo' => array('ANNONCES'),
'getAnnoncesBoamp' => array('ANNONCES'),
'getAnnoncesLegales' => array('ANNONCES'),
'getAnnoncesNum' => array('ANNONCES'),
'getAvisRncs' => array('AVISRNCS'),
'getBanques' => array('BANQUES'),
'getBilan' => array('LIASSE'),
'getDirigeants' => array('DIRIGEANTS'),
'getIdentite' => array('IDENTITE'),
'getIdentiteProcol' => array('IDPROCOL'),
'getIndiScore' => array('INDISCORE1', 'INDISCORE2', 'INDISCORE3'),
'getInfosBourse' => array('BOURSE'),
'getInfosReg' => array('INFOSREG'),
'getLiasseInfos' => array(),
'getLienRef' => array('LIENS'),
'getLiens' => array('LIENS'),
'getLiensById' => array('LIENS'),
'getListeBilans' => array('LIASSE'),
'getListeCompetences' => array('COMPETENCES'),
'getListeEtablissements' => array('ETABLISSEMENTS'),
'getListeEvenements' => array('EVENINSEE'),
'getRapport' => array('INDISCORE3'),
'getRatios' => array('RATIOS'),
'getSubventionDetail' => array(''),
'getSubventionList' => array(''),
'getTVA' => array(''),
'getValo' => array('VALORISATION'),
'isSirenExistant' => array(''),
'searchAutreId' => array('SEARCHENT'),
'searchDir' => array('SEARCHDIR'),
'searchEntreprise' => array('SEARCHENT'),
'searchNomAdr' => array('SEARCHENT'),
'searchRefClient' => array(),
'searchSiren' => array('SEARCHENT'),
'searchTelFax' => array('SEARCHENT'),
);
$display = array();
foreach ( $listdroit as $droit ) {
foreach ( $assoc as $l => $d ) {
if ( in_array(strtoupper($droit), $d) ) {
$display[] = array(
'label' => $l,
'droit' => $droit,
);
}
}
}
$this->view->display = $display;
}
}