Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 1053 Rev 1054
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 true; //$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
		return $resultat['identifie'];
59
		return $resultat['identifie'];
60
	}
60
	}
61
 
61
 
62
	private function analyserCookies() {
62
	private function analyserCookies() {
63
		$this->analyserCookiesIdentite();
63
		$this->analyserCookiesIdentite();
64
		$this->analyserCookiesNiveau();
64
		$this->analyserCookiesNiveau();
65
	}
65
	}
66
 
66
 
67
	private function analyserCookiesIdentite() {
67
	private function analyserCookiesIdentite() {
68
		if ($this->identifie == false) {
68
		if ($this->identifie == false) {
69
			if (isset($_COOKIE[$this->nomCookieUtilisateurPersistant])) {
69
			if (isset($_COOKIE[$this->nomCookieUtilisateurPersistant])) {
70
				$idTela = $_COOKIE[$this->nomCookieUtilisateurPersistant];
70
				$idTela = $_COOKIE[$this->nomCookieUtilisateurPersistant];
71
				$this->extraireMdpEtCourriel($idTela);
71
				$this->extraireMdpEtCourriel($idTela);
72
			} else if (isset($_COOKIE[$this->nomCookieUtilisateur])) {
72
			} else if (isset($_COOKIE[$this->nomCookieUtilisateur])) {
73
				$idTela = $_COOKIE[$this->nomCookieUtilisateur];
73
				$idTela = $_COOKIE[$this->nomCookieUtilisateur];
74
				$this->extraireMdpEtCourriel($idTela);
74
				$this->extraireMdpEtCourriel($idTela);
75
			}
75
			}
76
		}
76
		}
77
	}
77
	}
78
 
78
 
79
	private function extraireMdpEtCourriel($idTela) {
79
	private function extraireMdpEtCourriel($idTela) {
80
		$this->md5Mdp = substr($idTela, 0, 32);
80
		$this->md5Mdp = substr($idTela, 0, 32);
81
		$this->courriel = substr($idTela, 32);
81
		$this->courriel = substr($idTela, 32);
82
		$this->identifie = true;
82
		$this->identifie = true;
83
	}
83
	}
84
 
84
 
85
	private function analyserCookiesNiveau() {
85
	private function analyserCookiesNiveau() {
86
		$this->niveau = $this->niveauDefaut;
86
		$this->niveau = $this->niveauDefaut;
87
		if (isset($_COOKIE[$this->nomCookieNiveau])) {
87
		if (isset($_COOKIE[$this->nomCookieNiveau])) {
88
			$this->niveau = $_COOKIE[$this->nomCookieNiveau];
88
			$this->niveau = $_COOKIE[$this->nomCookieNiveau];
89
		}
89
		}
90
	}
90
	}
91
}
91
}
92
?>
92
?>