webservice/application/controllers/UserController.php

134 lines
4.9 KiB
PHP
Raw Permalink Normal View History

2013-11-05 12:18:30 +01:00
<?php
class UserController extends Zend_Controller_Action
{
2016-11-29 15:10:11 +01:00
public function indexAction()
2013-11-05 12:18:30 +01:00
{
2016-11-29 15:10:11 +01:00
}
2013-11-05 12:18:30 +01:00
2016-11-29 15:10:11 +01:00
public function loginAction()
{
$this->_helper->layout()->disableLayout();
$this->view->headLink()->appendStylesheet('/assets/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/>";
}
}
}
}
2013-11-05 12:18:30 +01:00
}
public function logoutAction()
{
2016-11-29 15:10:11 +01:00
$this->_helper->layout()->disableLayout();
Zend_Auth::getInstance()->clearIdentity();
2013-11-05 12:18:30 +01:00
}
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);
2016-10-03 11:25:05 +02:00
/**
* @var \Doctrine\DBAL\Connection $conn
*/
$conn = Zend_Registry::get('doctrine');
$userSql = "SELECT * FROM sdv1.utilisateurs WHERE id=:id";
$stmt = $conn->prepare($userSql);
$stmt->bindValue('id', $identity->id);
$stmt->execute();
$user = $stmt->fetch(\PDO::FETCH_OBJ);
$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();
2016-11-29 15:10:11 +01:00
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;
}
2016-11-29 15:10:11 +01:00
}