Rev 1053 | Rev 1239 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
class Utilisateur {
const NIVEAU_DEBUTANT = 1;
const NIVEAU_INTERMEDIAIRE = 2;
const NIVEAU_EXPERT = 3;
private $dureeSauvegarde = null;
private $nomCookieUtilisateur = '';
private $nomCookieUtilisateurPersistant = '';
private $nomCookieNiveau = '';
private $niveauDefaut = '';
private $urlWsAnnuaire = '';
private $restClient = null;
private $niveau = null;
private $identifie = false;
private $courriel = null;
private $md5Mdp = null;
public function __construct(Conteneur $conteneur) {
$this->dureeSauvegarde = $conteneur->getParametre('cookies.duree');
$this->nomCookieUtilisateur = $conteneur->getParametre('cookies.utilisateur');
$this->nomCookieUtilisateurPersistant = $conteneur->getParametre('cookies.utilisateurPersistant');
$this->nomCookieNiveau = $conteneur->getParametre('cookies.niveau');
$this->niveauDefaut = $conteneur->getParametre('utilisateur.niveau.defaut');
$this->urlWsAnnuaire = $conteneur->getParametre('baseUrlServicesAnnuaireTpl');
$this->restClient = $conteneur->getRestClient();
$this->analyserCookies();
}
public function getCourriel() {
return $this->courriel;
}
public function getNiveau() {
return $this->niveau;
}
public function sauver() {
setcookie($this->nomCookieNiveau, time()+$this->dureeSauvegarde, '/');
}
public function etreIdentifie() {
$this->analyserCookies();
return $this->identifie;
}
public function connecter($courriel, $mdp, $persistance = false) {
$url = sprintf($this->urlWsAnnuaire, 'utilisateur');
$donnees['methode'] = 'connexion';
$donnees['courriel'] = $courriel;
$donnees['mdp'] = $mdp;
$donnees['persistance'] = $persistance;
$json = $this->restClient->ajouter($url, $donnees);
$forceTableauAssociatif = true;
$resultat = json_decode($json, $forceTableauAssociatif);
return $resultat['identifie'];
}
private function analyserCookies() {
$this->analyserCookiesIdentite();
$this->analyserCookiesNiveau();
}
private function analyserCookiesIdentite() {
if ($this->identifie == false) {
if (isset($_COOKIE[$this->nomCookieUtilisateurPersistant])) {
$idTela = $_COOKIE[$this->nomCookieUtilisateurPersistant];
$this->extraireMdpEtCourriel($idTela);
} else if (isset($_COOKIE[$this->nomCookieUtilisateur])) {
$idTela = $_COOKIE[$this->nomCookieUtilisateur];
$this->extraireMdpEtCourriel($idTela);
}
}
}
private function extraireMdpEtCourriel($idTela) {
$this->md5Mdp = substr($idTela, 0, 32);
$this->courriel = substr($idTela, 32);
$this->identifie = true;
}
private function analyserCookiesNiveau() {
$this->niveau = $this->niveauDefaut;
if (isset($_COOKIE[$this->nomCookieNiveau])) {
$this->niveau = $_COOKIE[$this->nomCookieNiveau];
}
}
}
?>