Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 520 | Rev 1053 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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