Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 291 | Rev 536 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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();
46
		return $this->identifie;
47
	}
291 jpm 48
 
520 jpm 49
	public function connecter($courriel, $mdp, $persistance = false) {
50
		$url = sprintf($this->urlWsAnnuaire, 'Utilisateur');
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
		Debug::printr($resultat);
60
		return $resultat['identifie'];
61
	}
62
 
63
	private function analyserCookies() {
64
		$this->analyserCookiesIdentite();
65
		$this->analyserCookiesNiveau();
66
	}
67
 
68
	private function analyserCookiesIdentite() {
69
		if ($this->identifie == false) {
70
			if (isset($_COOKIE[$this->nomCookieUtilisateurPersistant])) {
71
				$idTela = $_COOKIE[$this->nomCookieUtilisateurPersistant];
72
				$this->md5Mdp = substr($idTela, 0, 32);
73
				$this->courriel = substr($idTela, 32);
74
				$this->identifie = true;
75
			} else if (isset($_COOKIE[$this->nomCookieUtilisateur])) {
76
				$this->courriel = $_COOKIE[$this->nomCookieUtilisateur];
77
				$this->identifie = true;
78
			}
79
		}
80
	}
81
 
82
	private function analyserCookiesNiveau() {
83
		$this->niveau = $this->niveauDefaut;
84
		if (isset($_COOKIE[$this->nomCookieNiveau])) {
85
			$this->niveau = $_COOKIE[$this->nomCookieNiveau];
86
		}
87
	}
88
}
89
?>