291 |
jpm |
1 |
<?php
|
|
|
2 |
class Utilisateur {
|
|
|
3 |
|
|
|
4 |
const NIVEAU_DEBUTANT = 1;
|
|
|
5 |
const NIVEAU_INTERMEDIAIRE = 2;
|
|
|
6 |
const NIVEAU_EXPERT = 3;
|
|
|
7 |
|
|
|
8 |
private $dureeSauvegarde = null;
|
520 |
jpm |
9 |
private $nomCookieUtilisateur = '';
|
|
|
10 |
private $nomCookieUtilisateurPersistant = '';
|
|
|
11 |
private $nomCookieNiveau = '';
|
|
|
12 |
private $niveauDefaut = '';
|
|
|
13 |
private $urlWsAnnuaire = '';
|
|
|
14 |
private $restClient = null;
|
|
|
15 |
|
291 |
jpm |
16 |
private $niveau = null;
|
520 |
jpm |
17 |
private $identifie = false;
|
|
|
18 |
private $courriel = null;
|
|
|
19 |
private $md5Mdp = null;
|
291 |
jpm |
20 |
|
520 |
jpm |
21 |
public function __construct(Conteneur $conteneur) {
|
|
|
22 |
$this->dureeSauvegarde = $conteneur->getParametre('cookies.duree');
|
|
|
23 |
$this->nomCookieUtilisateur = $conteneur->getParametre('cookies.utilisateur');
|
|
|
24 |
$this->nomCookieUtilisateurPersistant = $conteneur->getParametre('cookies.utilisateurPersistant');
|
|
|
25 |
$this->nomCookieNiveau = $conteneur->getParametre('cookies.niveau');
|
|
|
26 |
$this->niveauDefaut = $conteneur->getParametre('utilisateur.niveau.defaut');
|
|
|
27 |
$this->urlWsAnnuaire = $conteneur->getParametre('baseUrlServicesAnnuaireTpl');
|
|
|
28 |
$this->restClient = $conteneur->getRestClient();
|
|
|
29 |
$this->analyserCookies();
|
|
|
30 |
}
|
291 |
jpm |
31 |
|
520 |
jpm |
32 |
public function getCourriel() {
|
|
|
33 |
return $this->courriel;
|
291 |
jpm |
34 |
}
|
|
|
35 |
|
|
|
36 |
public function getNiveau() {
|
|
|
37 |
return $this->niveau;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public function sauver() {
|
520 |
jpm |
41 |
setcookie($this->nomCookieNiveau, time()+$this->dureeSauvegarde, '/');
|
291 |
jpm |
42 |
}
|
|
|
43 |
|
520 |
jpm |
44 |
public function etreIdentifie() {
|
|
|
45 |
$this->analyserCookies();
|
1054 |
raphael |
46 |
return $this->identifie;
|
520 |
jpm |
47 |
}
|
291 |
jpm |
48 |
|
520 |
jpm |
49 |
public function connecter($courriel, $mdp, $persistance = false) {
|
536 |
jpm |
50 |
$url = sprintf($this->urlWsAnnuaire, 'utilisateur');
|
520 |
jpm |
51 |
$donnees['methode'] = 'connexion';
|
|
|
52 |
$donnees['courriel'] = $courriel;
|
|
|
53 |
$donnees['mdp'] = $mdp;
|
|
|
54 |
$donnees['persistance'] = $persistance;
|
|
|
55 |
|
|
|
56 |
$json = $this->restClient->ajouter($url, $donnees);
|
|
|
57 |
$forceTableauAssociatif = true;
|
|
|
58 |
$resultat = json_decode($json, $forceTableauAssociatif);
|
|
|
59 |
return $resultat['identifie'];
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
private function analyserCookies() {
|
|
|
63 |
$this->analyserCookiesIdentite();
|
|
|
64 |
$this->analyserCookiesNiveau();
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
private function analyserCookiesIdentite() {
|
|
|
68 |
if ($this->identifie == false) {
|
|
|
69 |
if (isset($_COOKIE[$this->nomCookieUtilisateurPersistant])) {
|
|
|
70 |
$idTela = $_COOKIE[$this->nomCookieUtilisateurPersistant];
|
536 |
jpm |
71 |
$this->extraireMdpEtCourriel($idTela);
|
520 |
jpm |
72 |
} else if (isset($_COOKIE[$this->nomCookieUtilisateur])) {
|
536 |
jpm |
73 |
$idTela = $_COOKIE[$this->nomCookieUtilisateur];
|
|
|
74 |
$this->extraireMdpEtCourriel($idTela);
|
520 |
jpm |
75 |
}
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
|
536 |
jpm |
79 |
private function extraireMdpEtCourriel($idTela) {
|
|
|
80 |
$this->md5Mdp = substr($idTela, 0, 32);
|
|
|
81 |
$this->courriel = substr($idTela, 32);
|
|
|
82 |
$this->identifie = true;
|
|
|
83 |
}
|
|
|
84 |
|
520 |
jpm |
85 |
private function analyserCookiesNiveau() {
|
|
|
86 |
$this->niveau = $this->niveauDefaut;
|
|
|
87 |
if (isset($_COOKIE[$this->nomCookieNiveau])) {
|
|
|
88 |
$this->niveau = $_COOKIE[$this->nomCookieNiveau];
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
?>
|