Gestion du compte utilisateur

This commit is contained in:
Michael RICOIS 2011-05-03 12:49:43 +00:00
parent 72d1f1857e
commit 2ef7c9a768
4 changed files with 171 additions and 37 deletions

View File

@ -1,25 +1,116 @@
<?php
require_once 'Web/Forms/Login.php';
require_once 'Web/WebAuthAdapter.php';
require_once 'Scores/Utilisateur.php';
require_once 'Scores/WsScores.php';
class UserController extends Zend_Controller_Action {
public function init()
{
class UserController extends Zend_Controller_Action
{
protected function updateProfil($login, $password)
{
Zend_Registry::get('firebug')->info('updateProfil');
$ws = new WsScores();
$InfosLogin = $ws->getInfosLogin($login);
$identity = new stdClass;
$identity->username = $login;
$identity->password = $password; // @todo : Hash ?
$identity->email = $InfosLogin->result->email;
$identity->profil = $InfosLogin->result->profil;
$identity->pref = $InfosLogin->result->pref;
$identity->droits = $InfosLogin->result->droits;
$identity->droitsClients = $InfosLogin->result->droitsClients;
$identity->nom = $InfosLogin->result->nom;
$identity->prenom = $InfosLogin->result->prenom;
$identity->tel = $InfosLogin->result->tel;
$identity->fax = $InfosLogin->result->fax;
$identity->mobile = $InfosLogin->result->mobile;
$identity->id = $InfosLogin->result->id;
$identity->idClient = $InfosLogin->result->idClient;
$identity->reference = $InfosLogin->result->reference;
$identity->nbReponses = $InfosLogin->result->nbReponses;
$identity->typeScore = $InfosLogin->result->typeScore;
$identity->timeout = (!empty($InfosLogin->result->timeout)) ?
$InfosLogin->result->timeout : 1800;
$identity->modeEdition = false;
return $identity;
}
public function init(){}
/**
* Affiche le fomulaire d'edition des paramètres utilisateur
*/
public function indexAction()
{
$this->view->headLink()->appendStylesheet('/themes/default/styles/form.css', 'all');
$this->view->headLink()
->appendStylesheet('/themes/default/styles/user.css', 'all')
->appendStylesheet('/themes/default/styles/form.css', 'all');
$this->view->headScript()
->appendFile('/themes/default/scripts/user.js', 'text/javascript');
$request = $this->getRequest();
$action = $request->getParam('action', '');
$messages = '';
$isProfilUpdated = true;
$isPasswordUpdated = true;
$updateResult = false;
require_once 'Scores/WsScores.php';
$ws = new WsScores();
if ($request->isPost()) {
$login = $request->getParam('login', '');
$options = $request->getParam('frmOptions', '');
$action = $options['action'];
//Gestion mode edition en SESSION
if ($action=='update') {
$modeEdition = $request->getParam('modeEdition', false);
if ($modeEdition){
$auth = Zend_Auth::getInstance();
$identity = $auth->getIdentity();
$identity->modeEdition = true;
$auth->getStorage()->write($identity);
}
}
//Enregistrement des données new & update
if (in_array($action, array('new','update'))) {
$infos = new stdClass();
$infos->idClient = $options['idClient'];
$infos->nom = $options['nom'];
$infos->prenom = $options['prenom'];
$infos->reference = $options['reference'];
$infos->email = $options['email'];
$infos->tel_fix = $options['tel_fix'];
$infos->tel_fax = $options['tel_fax'];
$infos->tel_mob = $options['tel_mob'];
$infos->rech_nbrep = $options['rech_nbrep'];
$infos->formatMail = $options['formatMail'];
$infos->password = '';
if ($options['changepwd']==1){
$infos->password = $options['password'];
}
$infos->droits = $options['droits'];
$infos->pref = $options['pref'];
$ws = new WsScores();
$infos = $ws->setInfosLogin($login, $action, $infos);
$isProfilUpdated = true;
$message = 'Erreur lors de la mise à jour du compte !';
if ($infos->result){
$updateResult = true;
$message = 'Compte mis à jour.';
}
}
}
//Liste de tous les droits
$listeDroits = $ws->getListeDroits();
$droitsLib = array();
foreach($listeDroits->item as $droit) {
$droitsLib[$droit->code] = $droit->desc;
$droitsLib[strtoupper($droit->code)] = $droit->desc;
}
$this->view->assign('droitsLib', $droitsLib);
@ -27,12 +118,23 @@ class UserController extends Zend_Controller_Action {
$listePrefs = $ws->getListePrefs();
$prefsLib = array();
foreach($listePrefs->item as $pref) {
$prefsLib[$pref->code] = $pref->desc;
$prefsLib[strtoupper($pref->code)] = $pref->desc;
}
$this->view->assign('prefsLib', $prefsLib);
//Récupération des informations de l'identité
$auth = Zend_Auth::getInstance();
$identity = $auth->getIdentity();
if ($isProfilUpdated && $updateResult) {
$identity = $this->updateProfil($identity->username, $identity->password);
$auth->getStorage()->write($identity);
}
Zend_Registry::get('firebug')->info($identity);
if ($isProfilUpdated || $isPasswordUpdated) {
$this->view->assign('message', $message);
}
$isAdmin = false;
if ($identity->profil == 'Administrateur'
|| $identity->profil == 'SuperAdministrateur') {
@ -41,11 +143,11 @@ class UserController extends Zend_Controller_Action {
$this->view->assign('options', $identity);
$this->view->assign('isAdmin', $isAdmin);
$this->view->assign('loginVu', $identity->username);
if (!isset($_REQUEST['action']) || $_REQUEST['action']!='new') {
if (!empty($action) || $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('action', 'update');
$this->view->assign('pref', explode(' ',$identity->pref));
} else {
$reponse = $ws->getNextLogin($loginVu);
@ -54,14 +156,7 @@ class UserController extends Zend_Controller_Action {
$this->view->assign('action', 'new');
$this->view->assign('pref', array());
}
}
public function saveAction()
{
}
public function changepwdAction()
{

View File

@ -1,13 +1,18 @@
<div id="center">
<?php if (!empty($this->message)) { ?>
<div style="margin:5px; padding: 0pt 0.7em;" class="ui-state-highlight ui-corner-all">
<p><span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-info"></span>
<?=$this->message?>
</p></div>
<?php } ?>
<h1 class="titre">PROFIL UTILISATEUR</h1>
<div class="paragraph">
<form id="moncompte" name="moncompte" action="/user/save" method="post">
<input type="hidden" name="siret" value="<?=$this->siret?>"/>
<input type="hidden" name="id" value="<?=$this->idEntreprise?>"/>
<form id="moncompte" name="moncompte" action="/user" method="post">
<input type="hidden" name="referer" value="<?=$_REQUEST['referer']?>"/>
<input type="hidden" name="login" value="<?=$this->$loginVu?>"/>
<input type="hidden" name="login" value="<?=$this->loginVu?>"/>
<input type="hidden" name="frmOptions[idClient]" value="<?=$this->options->idClient?>"/>
<input type="hidden" name="frmOptions[action]" value="<?=$this->action?>"/>
@ -129,11 +134,11 @@ foreach($opts as $opt)
<?php
foreach ($this->droitsClients as $droit) {
$check = '';
if (in_array($droit, $this->droits)){
if (in_array(strtoupper($droit), $this->droits)){
$check = ' checked';
}
?>
<input type="checkbox" name="frmOptions[droits][]" value="<?php echo strtoupper($droit)?>" <?php echo $check?> class="noborder"/>
<input type="checkbox" name="frmOptions[droits][]" value="<?=strtoupper($droit)?>"<?=$check?> class="noborder"/>
<?php echo $this->droitsLib[strtoupper($droit)]?><br/>
<?php }?>
</div>
@ -142,11 +147,11 @@ foreach ($this->droitsClients as $droit) {
<div class="infoData last">
<?php
foreach ($this->prefsLib as $code => $lib) {
if (in_array($code, $this->pref)) {
if (in_array(strtoupper($code), $this->pref)) {
$check = ' checked';
}
?>
<input type="checkbox" name="frmOptions[droits][]" value="<?php echo strtoupper($code)?>" <?php echo $check?> class="noborder"/>
<input type="checkbox" name="frmOptions[pref][]" value="<?=strtoupper($code)?>"<?=$check?> class="noborder"/>
<?php echo $lib?><br/>
<?php }?>
</div>
@ -158,24 +163,27 @@ if ( $this->options->idClient == 1 && !in_array('edition',$this->droits) ) {
<div class="infoTitle StyleInfoLib">Mode Edition</div>
<div class="infoData last">
<?php
$check = false;
$check = '';
if ( $this->options->modeEdition==true ) {
$check = true;
$check = ' checked';
}
?>
<input type="checkbox" name="modeEdition" value="1" <?php echo $check?> class="noborder"/>
<input type="checkbox" name="modeEdition" value="1"<?=$check?> class="noborder"/>
</div>
<?php }?>
</div>
<div class="submit"><p class="submit-button"><input type="submit" class="button" value="Sauver"/></p></div>
</form>
<?php
echo "<pre>";
//print_r($this->options);
echo "</pre>";
?>
</div>
</div>
<div id="dialog" title="Modifier le mot de passe">
<form>
<label for="npass1">Nouveau mot de passe</label><br/>
<input type="password" name="npass1" size="15" maxlength="32"/><br/>
<label for="npass2">Répéter le nouveau mot de passe</label><br/>
<input type="password" name="npass2" size="15" maxlength="32"/><br/>
<span id="form-message"></span>
</form>
</div>

View File

@ -0,0 +1,30 @@
$(document).ready(function(){
$('#password').live('click', function(){
var dialogOpts = {
bgiframe: true,
autoOpen: false,
height: 180,
modal: true,
buttons: {
'Modifier': function() {
var pass = $('input[name=npass1]').val();
if (pass != $('input[name=npass2]').val()) {
$('#form-message').html('Mots de passe différents.');
} else {
$('input[name="frmOptions[changepwd]"]').val('1');
$('input[name="frmOptions[password]"]').val(pass);
$('#password').html('Sauver pour enregistrer la modification du mot de passe');
$(this).dialog('close');
}
},
'Annuler': function() { $(this).dialog('close'); }
},
close: function() { $('#dialog').remove(); }
};
$("#dialog").dialog(dialogOpts);
$("#dialog").dialog('open');
return false;
});
});

View File

@ -0,0 +1 @@
#dialog { display:none; }