Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1497 Rev 1508
1
<?php
1
<?php
2
/**
2
/**
3
 * Service d'itentification d'un utilisateur.
3
 * Service d'itentification d'un utilisateur.
4
 * Encodage en entrée : utf8
4
 * Encodage en entrée : utf8
5
 * Encodage en sortie : utf8
5
 * Encodage en sortie : utf8
6
 * Cas d'utilisation :
6
 * Cas d'utilisation :
7
 * 1: Aucun login ni mot de passe transmis
7
 * 1: Aucun login ni mot de passe transmis
8
 * 	1: L'application retourne l'identifiant de session en cours
8
 * 	1: L'application retourne l'identifiant de session en cours
9
 * 	2: Une identification est toujours active, cette identification est retournée
9
 * 	2: Une identification est toujours active, cette identification est retournée
10
 * 
10
 * 
11
 * 2: Ce service recoit un login et un mot de passe
11
 * 2: Ce service recoit un login et un mot de passe
12
 * 	1 : On tente d'identifier l'utilisateur
12
 * 	1 : On tente d'identifier l'utilisateur
13
 * 	2 : Si réussi, l'état passe à : connecté
13
 * 	2 : Si réussi, l'état passe à : connecté
14
 * 	3 : sinon, l'état passe à : pas connecté
14
 * 	3 : sinon, l'état passe à : pas connecté
15
 * 
15
 * 
16
 * 3: Ce service reçoit un identifiant (différent du login) et aucun mot de passe :
16
 * 3: Ce service reçoit un identifiant (différent du login) et aucun mot de passe :
17
 * 	1 : Déconnexion
17
 * 	1 : Déconnexion
18
 * 
18
 * 
19
 *  En résumé, utilisation des URLs :
19
 *  En résumé, utilisation des URLs :
20
 *  /CoelUtilisateur/					: retour identifiant de session si jamais connecté, sinon retour de l'id (+ login et mot de passe)
20
 *  /CoelUtilisateur/					: retour identifiant de session si jamais connecté, sinon retour de l'id (+ login et mot de passe)
21
 *  /CoelUtilisateur/ * / * /			: idem ci-dessus
21
 *  /CoelUtilisateur/ * / * /			: idem ci-dessus
22
 *  /CoelUtilisateur/id					: déconexion
22
 *  /CoelUtilisateur/id					: déconexion
23
 *  /CoelUtilisateur/login/mot_de_passe	: connexion
23
 *  /CoelUtilisateur/login/mot_de_passe	: connexion
24
 *
24
 *
25
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
25
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
26
 * @author David DELON <david.delon@clapas.net>abstract 
26
 * @author David DELON <david.delon@clapas.net>abstract 
27
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
27
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
28
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
28
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
29
 * @version $Id$
29
 * @version $Id$
30
 * @copyright 2009
30
 * @copyright 2009
31
 */
31
 */
32
class CoelUtilisateur extends Coel { 
32
class CoelUtilisateur extends Coel { 
-
 
33
	
-
 
34
	private $licence_acceptee = false;
33
	
35
	
34
	// TODO : controle systematique... dans tous les services si connected : name cookie = name service
36
	// TODO : controle systematique... dans tous les services si connected : name cookie = name service
35
	public function getRessource(){
37
	public function getRessource(){
36
		$this->getElement(array('*','*'));
38
		$this->getElement(array('*','*'));
37
	}	
39
	}	
38
 
40
 
39
	public function getElement($param){
41
	public function getElement($param){
40
		$identification = false;
42
		$identification = false;
41
		$info = array();
43
		$info = array();
42
		
44
		
43
		// Si la licence n'a pas été accepté nous réinitialisons tout
45
		// Si la licence n'a pas été accepté nous réinitialisons tout
44
		if (!isset($_COOKIE['coel_licence']) || (isset($_COOKIE['coel_licence']) && $_COOKIE['coel_licence'] != 1)) {
46
		if (!isset($param[2]) && (!isset($_COOKIE['coel_licence']) || (isset($_COOKIE['coel_licence']) && $_COOKIE['coel_licence'] != 1))) {
45
			$this->deconnecterUtilisateur();
47
			$this->deconnecterUtilisateur();
46
		}
48
		}
47
		
49
		
48
		// S'il y a 3 paramètres, c'est qu'on cherche à mettre à jour la licence
50
		// S'il y a 3 paramètres, c'est qu'on cherche à mettre à jour la licence
49
		if (isset($param[2])) {
51
		if (isset($param[2])) {
-
 
52
			$this->debug[] = "Licence acceptee";
-
 
53
			$this->licence_acceptee = true; 
50
			// Mise à jour de la licence
54
			// Mise à jour de la licence
51
			if (!$this->accepterLicence($param[0]))	{
55
			if (!$this->accepterLicence($param[0]))	{
52
				$this->debug[] = "Erreur de mise à jour licence utilisateur";
56
				$this->debug[] = "Erreur de mise à jour licence utilisateur";
53
			}
57
			}
54
		} else if (isset($param[1])) { // Non connecté : vérification
58
		} else if (isset($param[1])) { // Non connecté : vérification
55
			if (!$this->getUtilisateur()) { // Si non identifié
59
			if (!$this->getUtilisateur()) { // Si non identifié
56
				$id = null;
60
				$id = null;
57
				if ($param[0] == '*' && $param[1] == '*') {	// Tentative d'identification depuis les cookies permanents
61
				if ($param[0] == '*' && $param[1] == '*') {	// Tentative d'identification depuis les cookies permanents
58
					if (isset($_COOKIE['coel_login']) && ($this->souvenirUtilisateur($_COOKIE['coel_login'], $_COOKIE['coel_mot_de_passe'])))  {
62
					if (isset($_COOKIE['coel_login']) && ($this->souvenirUtilisateur($_COOKIE['coel_login'], $_COOKIE['coel_mot_de_passe'])))  {
59
						$id = $this->getUtilisateurId();
63
						$id = $this->getUtilisateurId();
60
						$identification = true;
64
						$identification = true;
61
						$info = array($id, $identification, $this->getUtilisateurNomComplet(), $this->getUtilisateurPrenom(), $this->getUtilisateurNom(), $this->getParametre());
65
						$info = array($id, $identification, $this->getUtilisateurNomComplet(), $this->getUtilisateurPrenom(), $this->getUtilisateurNom(), $this->getParametre());
62
					}
66
					}
63
				} else if ($this->connecterUtilisateur($param[0], $param[1], 1)) { // Tentative d'identification depuis les paramêtres passés dans l'url du service
67
				} else if ($this->connecterUtilisateur($param[0], $param[1], 1)) { // Tentative d'identification depuis les paramêtres passés dans l'url du service
64
					$id = $this->getUtilisateurId();
68
					$id = $this->getUtilisateurId();
65
					$identification = true;
69
					$identification = true;
66
					$info = array($id, $identification, $this->getUtilisateurNomComplet(), $this->getUtilisateurPrenom(), $this->getUtilisateurNom(), $this->getParametre());
70
					$info = array($id, $identification, $this->getUtilisateurNomComplet(), $this->getUtilisateurPrenom(), $this->getUtilisateurNom(), $this->getParametre());
67
				} 
71
				} 
68
				
72
				
69
				// L'identification a échouée, nous retournons un session_id comme identifiant
73
				// L'identification a échouée, nous retournons un session_id comme identifiant
70
				if (is_null($id)) {					
74
				if (is_null($id)) {					
71
					$id = session_id();
75
					$id = session_id();
72
					$identification = false;
76
					$identification = false;
73
					$info = array($id, $identification);
77
					$info = array($id, $identification);
74
				}
78
				}
75
			} else { // Déjà identifié
79
			} else { // Déjà identifié
76
				$id = $this->getUtilisateurId();
80
				$id = $this->getUtilisateurId();
77
				$identification = true;
81
				$identification = true;
78
				$info = array($id, $identification, $this->getUtilisateurNomComplet(), $this->getUtilisateurPrenom(), $this->getUtilisateurNom(), $this->getParametre());
82
				$info = array($id, $identification, $this->getUtilisateurNomComplet(), $this->getUtilisateurPrenom(), $this->getUtilisateurNom(), $this->getParametre());
79
			}
83
			}
80
		} else { // Déconnexion
84
		} else { // Déconnexion
81
			$this->deconnecterUtilisateur();
85
			$this->deconnecterUtilisateur();
82
			$id = session_id();
86
			$id = session_id();
83
			$identification = false;
87
			$identification = false;
84
			$info = array($id, $identification);
88
			$info = array($id, $identification);
85
		}
89
		}
86
 
90
 
87
		array_unshift($info, $this->getLicence());
91
		array_unshift($info, $this->getLicence());
88
		
92
		
89
		// Envoie sur la sortie standard
93
		// Envoie sur la sortie standard
90
		$this->envoyer($info);
94
		$this->envoyer($info);
91
	}
95
	}
92
	
96
	
93
	private function getUtilisateurId() {
97
	private function getUtilisateurId() {
94
		if ($utilisateur = $this->getUtilisateur()) {
98
		if ($utilisateur = $this->getUtilisateur()) {
95
			return $utilisateur['id'];
99
			return $utilisateur['id'];
96
		} else {
100
		} else {
97
			return '';
101
			return '';
98
		}
102
		}
99
	}
103
	}
100
	
104
	
101
	private function getUtilisateurLogin() {
105
	private function getUtilisateurLogin() {
102
		if ($utilisateur = $this->getUtilisateur()) {
106
		if ($utilisateur = $this->getUtilisateur()) {
103
			return $utilisateur['login'];
107
			return $utilisateur['login'];
104
		} else {
108
		} else {
105
			return '';
109
			return '';
106
		}
110
		}
107
	}
111
	}
108
	
112
	
109
	private function getUtilisateurNomComplet() {
113
	private function getUtilisateurNomComplet() {
110
		if ($utilisateur = $this->getUtilisateur()) {
114
		if ($utilisateur = $this->getUtilisateur()) {
111
			return $utilisateur['nom_complet'];
115
			return $utilisateur['nom_complet'];
112
		} else {
116
		} else {
113
			return '';
117
			return '';
114
		}
118
		}
115
	}
119
	}
116
	
120
	
117
	private function getUtilisateurPrenom() {
121
	private function getUtilisateurPrenom() {
118
		if ($utilisateur = $this->getUtilisateur()) {
122
		if ($utilisateur = $this->getUtilisateur()) {
119
			return $utilisateur['prenom'];
123
			return $utilisateur['prenom'];
120
		} else {
124
		} else {
121
			return '';
125
			return '';
122
		}
126
		}
123
	}
127
	}
124
	
128
	
125
	private function getUtilisateurNom() {
129
	private function getUtilisateurNom() {
126
		if ($utilisateur = $this->getUtilisateur()) {
130
		if ($utilisateur = $this->getUtilisateur()) {
127
			return $utilisateur['nom'];
131
			return $utilisateur['nom'];
128
		} else {
132
		} else {
129
			return '';
133
			return '';
130
		}
134
		}
131
	}
135
	}
132
	
136
	
133
	private function getParametre() {
137
	private function getParametre() {
134
		if ($utilisateur = $this->getUtilisateur()) {
138
		if ($utilisateur = $this->getUtilisateur()) {
135
			return $utilisateur['parametre'];
139
			return $utilisateur['parametre'];
136
		} else {
140
		} else {
137
			return '';
141
			return '';
138
		}
142
		}
139
	}
143
	}
140
	
144
	
141
	private function getLicence()	{
145
	private function getLicence()	{
142
		if (!empty($_SESSION['coel_utilisateur']))	{
146
		if (!empty($_SESSION['coel_utilisateur']))	{
143
			return (string) $_SESSION['coel_utilisateur']['licence'];
147
			return (string) $_SESSION['coel_utilisateur']['licence'];
144
		} else {
148
		} else {
145
			return '';
149
			return '';
146
		}
150
		}
147
	}
151
	}
148
		
152
		
149
	private function getInfosAnnuaire()	{
153
	private function getInfosAnnuaire()	{
150
		if (!empty($_SESSION['coel_infosAnnuaire']))	{
154
		if (!empty($_SESSION['coel_infosAnnuaire']))	{
151
			return $_SESSION['coel_infosAnnuaire'];
155
			return $_SESSION['coel_infosAnnuaire'];
152
		} else	{
156
		} else	{
153
			return '';
157
			return '';
154
		}
158
		}
155
	}
159
	}
156
 
160
 
157
	private function deconnecterUtilisateur() {
161
	private function deconnecterUtilisateur() {
158
		$_SESSION['coel_utilisateur'] = '';
162
		$_SESSION['coel_utilisateur'] = '';
159
		$_SESSION['coel_infosAnnuaire'] = '';
163
		$_SESSION['coel_infosAnnuaire'] = '';
160
		$this->supprimerCookie('coel_login');
164
		$this->supprimerCookie('coel_login');
161
		$this->supprimerCookie('coel_mot_de_passe');
165
		$this->supprimerCookie('coel_mot_de_passe');
162
		$this->supprimerCookie('coel_licence');
166
		$this->supprimerCookie('coel_licence');
163
		$this->supprimerCookie('coel_permanence');		
167
		$this->supprimerCookie('coel_permanence');		
164
	}
168
	}
165
	
169
	
166
	private function connecterUtilisateur($login, $mot_de_passe, $permanence = 1) {
170
	private function connecterUtilisateur($login, $mot_de_passe, $permanence = 1) {
167
		// Dans tous les cas, on récupère les informations de l'utilisateur présentes dans l'annuaire de Tela Botanica
171
		// Dans tous les cas, on récupère les informations de l'utilisateur présentes dans l'annuaire de Tela Botanica
168
		$infosAnnuaire = $this->obtenirInfosAnnuaire($login);
172
		$infosAnnuaire = $this->obtenirInfosAnnuaire($login);
169
		$this->setInfosAnnuaire($infosAnnuaire);
173
		$this->setInfosAnnuaire($infosAnnuaire);
170
 
174
 
171
		if ($mot_de_passe == 'debug' && $utilisateur_existant = $this->chargerUtilisateur($login)) {
175
		if ($mot_de_passe == 'debug' && $utilisateur_existant = $this->chargerUtilisateur($login)) {
172
			$this->setUtilisateur($utilisateur_existant, $permanence);
176
			$this->setUtilisateur($utilisateur_existant, $permanence);
173
			return true;
177
			return true;
174
		} else {
178
		} else {
175
			$mot_de_passe_sha1 = sha1($mot_de_passe);
179
			$mot_de_passe_sha1 = sha1($mot_de_passe);
176
			$mot_de_passe_md5 = md5($mot_de_passe);			
180
			$mot_de_passe_md5 = md5($mot_de_passe);			
177
			if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_sha1)) {
181
			if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_sha1)) {
178
				// OK, nous poursuivons
182
				// OK, nous poursuivons
179
			} else if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_md5)) {
183
			} else if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_md5)) {
180
				// Mise à jour du mot de passe md5 en sha1
184
				// Mise à jour du mot de passe md5 en sha1
181
				$this->mettreAJourMotDePasse($login, $mot_de_passe_md5, $mot_de_passe_sha1);
185
				$this->mettreAJourMotDePasse($login, $mot_de_passe_md5, $mot_de_passe_sha1);
182
				$utilisateur_existant['mot_de_passe'] = $mot_de_passe_sha1;
186
				$utilisateur_existant['mot_de_passe'] = $mot_de_passe_sha1;
183
			}
187
			}
184
			
188
			
185
			// Vérification de la nécessité de mettre à jour l'utilisateur du COEL vis à vis de l'annuaire de Tela Botanica
189
			// Vérification de la nécessité de mettre à jour l'utilisateur du COEL vis à vis de l'annuaire de Tela Botanica
186
			if (!is_null($infosAnnuaire) &&  $this->avoirBesoinMiseAJour($utilisateur_existant)) {
190
			if (!is_null($infosAnnuaire) &&  $this->avoirBesoinMiseAJour($utilisateur_existant)) {
-
 
191
				$this->debug[] = "Besoin d'une mise à jour";
187
				// Vérifions que la personne s'est bien identifiée
192
				// Vérifions que la personne s'est bien identifiée
188
				if ($infosAnnuaire['mot_de_passe'] == $mot_de_passe_md5) {
193
				if ($infosAnnuaire['mot_de_passe'] == $mot_de_passe_md5) {
-
 
194
					$this->debug[] = "Identification correcte avec md5";
189
					$utilisateur_existant = $this->getInfoAnnuaireCoelDepuisInfoAnnuaireDistant($mot_de_passe_sha1, $infosAnnuaire);
195
					$utilisateur_existant = $this->getInfoAnnuaireCoelDepuisInfoAnnuaireDistant($mot_de_passe_sha1, $infosAnnuaire);
190
					
196
					
191
					$presence_dans_coel = $this->verifierPresenceUtilisateur($infosAnnuaire['id']);
197
					$presence_dans_coel = $this->verifierPresenceUtilisateur($infosAnnuaire['id']);
-
 
198
					$this->debug[] = "Presence:$presence_dans_coel";
192
					if ($presence_dans_coel) {
199
					if ($presence_dans_coel) {
193
						// Nécessite de faire une mise à jour
200
						// Nécessite de faire une mise à jour
-
 
201
						$this->debug[] = "Mise à jour de l'utilisateur {$infosAnnuaire['id']}";
194
						$this->mettreAJourUtilisateur($mote_de_passe_sha1, $infosAnnuaire);
202
						$this->mettreAJourUtilisateur($mot_de_passe_sha1, $infosAnnuaire);
195
						$utilisateur_existant['licence'] = (int) $this->recupererLicenceUtilisateur($infosAnnuaire['id']);
203
						$utilisateur_existant['licence'] = (int) $this->recupererLicenceUtilisateur($infosAnnuaire['id']);
196
					} else {
204
					} else {
197
						// Nécessite d'ajouter le nouvel utilisateur
205
						// Nécessite d'ajouter le nouvel utilisateur
-
 
206
						$this->debug[] = "Ajout d'une nouvel utilisateur";
198
						$this->ajouterUtilisateurACoel($infosAnnuaire, $mot_de_passe_sha1);
207
						$this->ajouterUtilisateurACoel($infosAnnuaire, $mot_de_passe_sha1);
199
					}
208
					}
200
					
209
					
201
					$this->setUtilisateur($utilisateur_existant, $permanence);
210
					$this->setUtilisateur($utilisateur_existant, $permanence);
202
				} else {
211
				} else {
-
 
212
					$this->debug[] = "Identification INCORRECTE avec md5";
203
					return false;
213
					return false;
204
				}
214
				}
205
			} else if ($utilisateur_existant != false) {
215
			} else if ($utilisateur_existant != false) {
206
				// L'utilisateur est toutefois présent dans l'annuaire de COEL, est correctement identifié  et n'a pas besoin de mise à jour
216
				// L'utilisateur est toutefois présent dans l'annuaire de COEL, est correctement identifié  et n'a pas besoin de mise à jour
207
				$this->setUtilisateur($utilisateur_existant, $permanence);
217
				$this->setUtilisateur($utilisateur_existant, $permanence);
208
			} else {
218
			} else {
209
				// L'utilisateur n'existe ni dans l'annuaire de Tela Botanica ni dans celui de COEL
219
				// L'utilisateur n'existe ni dans l'annuaire de Tela Botanica ni dans celui de COEL
210
				return false;
220
				return false;
211
			}
221
			}
212
			
222
			
213
			// L'utilisateur a t il accepté la licence? Nécessaire pour être connecté!
223
			// L'utilisateur a t il accepté la licence? Nécessaire pour être connecté!
214
			if ($utilisateur_existant['licence'] == 1)	{
224
			if ($utilisateur_existant['licence'] == 1)	{
215
				return true;
225
				return true;
216
			} else {
226
			} else {
217
				return false;
227
				return false;
218
			}
228
			}
219
		}
229
		}
220
	}
230
	}
221
	
231
	
222
	private function avoirBesoinMiseAJour($info_annuaire_coel) {
232
	private function avoirBesoinMiseAJour($info_annuaire_coel) {
223
		$necessite_maj = false;
233
		$necessite_maj = false;
224
		if ($info_annuaire_coel == false) {
234
		if ($info_annuaire_coel == false) {
225
			// Le login et/ou le mot de passe a pu changer
235
			// Le login et/ou le mot de passe a pu changer
226
			$necessite_maj = true;
236
			$necessite_maj = true;
227
		} else {
237
		} else {
228
			$info_annuaire_distant = $this->getInfosAnnuaire();
238
			$info_annuaire_distant = $this->getInfosAnnuaire();
229
			if ($this->comparerInfosAnnuairesDistantEtCoel($info_annuaire_distant, $info_annuaire_coel) == false) {
239
			if ($this->comparerInfosAnnuairesDistantEtCoel($info_annuaire_distant, $info_annuaire_coel) == false) {
230
				$necessite_maj = true;
240
				$necessite_maj = true;
231
			}
241
			}
232
		}
242
		}
233
		return $necessite_maj;
243
		return $necessite_maj;
234
	}
244
	}
235
	
245
	
236
	private function comparerInfosAnnuairesDistantEtCoel($annuaire_distant, $annuaire_coel) {
246
	private function comparerInfosAnnuairesDistantEtCoel($annuaire_distant, $annuaire_coel) {
237
		$identique = true;
247
		$identique = true;
238
		$tableau_annuaire_distant = array('nom' => $annuaire_distant['nom'], 
248
		$tableau_annuaire_distant = array('nom' => $annuaire_distant['nom'], 
239
			'prenom' => $annuaire_distant['prenom'], 
249
			'prenom' => $annuaire_distant['prenom'], 
240
			'ville' => $annuaire_distant['ville'], 
250
			'ville' => $annuaire_distant['ville'], 
241
			'code_postal' => $annuaire_distant['code_postal']);
251
			'code_postal' => $annuaire_distant['code_postal']);
242
		$tableau_annuaire_coel = array('nom' => $annuaire_coel['nom'], 
252
		$tableau_annuaire_coel = array('nom' => $annuaire_coel['nom'], 
243
			'prenom' => $annuaire_coel['prenom'], 
253
			'prenom' => $annuaire_coel['prenom'], 
244
			'ville' => $annuaire_coel['ville'], 
254
			'ville' => $annuaire_coel['ville'], 
245
			'code_postal' => $annuaire_coel['code_postal']);
255
			'code_postal' => $annuaire_coel['code_postal']);
246
		foreach ($tableau_annuaire_distant as $cle => $valeur) {
256
		foreach ($tableau_annuaire_distant as $cle => $valeur) {
247
			if ($tableau_annuaire_coel[$cle] != $valeur) {
257
			if ($tableau_annuaire_coel[$cle] != $valeur) {
248
				$identique = false;
258
				$identique = false;
249
				break;
259
				break;
250
			}
260
			}
251
		}
261
		}
252
		return $identique;
262
		return $identique;
253
	}
263
	}
254
	
264
	
255
	private function getInfoAnnuaireCoelDepuisInfoAnnuaireDistant($mot_de_passe_sha1, $infos) {
265
	private function getInfoAnnuaireCoelDepuisInfoAnnuaireDistant($mot_de_passe_sha1, $infos) {
256
		$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom']; 
266
		$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom']; 
257
		$utilisateur_existant = array('id' => $infos['id'], 'login' =>	$infos['courriel'], 
267
		$utilisateur_existant = array('id' => $infos['id'], 'login' =>	$infos['courriel'], 
258
					   		'mot_de_passe' => $mot_de_passe_sha1,
268
					   		'mot_de_passe' => $mot_de_passe_sha1,
259
							'nom_complet' => $cp_fmt_nom_complet, 'nom' => $infos['nom'], 'prenom' => $infos['prenom'], 
269
							'nom_complet' => $cp_fmt_nom_complet, 'nom' => $infos['nom'], 'prenom' => $infos['prenom'], 
260
							'parametre' => '', 'licence' => '0');
270
							'parametre' => '', 'licence' => '0');
261
		return $utilisateur_existant;
271
		return $utilisateur_existant;
262
	}
272
	}
263
	
273
	
264
	private function verifierPresenceUtilisateur($id) {
274
	private function verifierPresenceUtilisateur($id) {
265
		$present = false;
275
		$present = false;
266
		
-
 
-
 
276
		$cp_ce_projet = $this->config['coel']['idProjetUtilisateurs'];
267
		$requete =	'SELECT COUNT(cp_id_personne) AS nbre '.
277
		$requete =	'SELECT COUNT(cp_id_personne) AS nbre '.
268
					'FROM coel_personne '.
278
					'FROM coel_personne '.
269
					"WHERE cp_ce_annuaire = {$this->bdd->quote($id)} ";
279
					"WHERE cp_ce_annuaire = {$this->bdd->quote($id)} ".
-
 
280
					"	AND cp_ce_annuaire = cp_id_personne ".
-
 
281
					"	AND cp_ce_projet = '$cp_ce_projet' ";
270
		try {
282
		try {
271
			$nbre = $this->bdd->query($requete)->fetchColumn();
283
			$nbre = $this->bdd->query($requete)->fetchColumn();
272
			if ($nbre === false) {
284
			if (0 == $nbre) {
273
				$this->debug[] = "L'utilisateur n'est pas présent dans l'annuaire de COEL.";
285
				$this->debug[] = "Utilisateur NON présent dans l'annuaire de COEL.";
274
			} else {
286
			} else if (1 == $nbre) {
-
 
287
				$this->debug[] = "Utilisateur présent dans l'annuaire de COEL.";
275
				$present = true;
288
				$present = true;
-
 
289
			} else if (false === $nbre) {
-
 
290
				$this->debug[] = "Erreur dans la requête de vérification de présence dans l'annuaire de COEL.";
276
			}
291
			}
277
		} catch (PDOException $e) {
292
		} catch (PDOException $e) {
278
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
293
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
279
		}
294
		}
280
		
295
		
281
		return $present;
296
		return $present;
282
	}
297
	}
283
	
298
	
284
	private function recupererLicenceUtilisateur($id) {
299
	private function recupererLicenceUtilisateur($id) {
-
 
300
		$cp_ce_projet = $this->config['coel']['idProjetUtilisateurs'];
285
		$requete =	'SELECT cp_mark_licence '.
301
		$requete =	'SELECT cp_mark_licence '.
286
					'FROM coel_personne '.
302
					'FROM coel_personne '.
287
					"WHERE cp_ce_annuaire = {$this->bdd->quote($id)} ";
303
					"WHERE cp_ce_annuaire = {$this->bdd->quote($id)} ".
-
 
304
					"	AND cp_ce_annuaire = cp_id_personne ".
-
 
305
					"	AND cp_ce_projet = '$cp_ce_projet' ";
288
		try {
306
		try {
289
			$licence = $this->bdd->query($requete)->fetchColumn();
307
			$licence = $this->bdd->query($requete)->fetchColumn();
290
			if ($licence === false) {
308
			if ($licence === false) {
291
				$this->debug[] = "La licence n'a pas pu être récupérée.";
309
				$this->debug[] = "La licence n'a pas pu être récupérée.";
292
				return 0;
310
				return 0;
293
			} else {
311
			} else {
294
				return $licence;
312
				return $licence;
295
			}
313
			}
296
		} catch (PDOException $e) {
314
		} catch (PDOException $e) {
297
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
315
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
298
		}
316
		}
299
	}
317
	}
300
	
318
	
301
	private function mettreAJourMotDePasse($login, $mot_de_passe_md5, $mot_de_passe_sha1) {
319
	private function mettreAJourMotDePasse($login, $mot_de_passe_md5, $mot_de_passe_sha1) {
302
		try {
320
		try {
-
 
321
		   	$cp_ce_projet = $this->config['coel']['idProjetUtilisateurs'];
303
		   	$requete = 	'UPDATE coel_personne '.
322
			$requete = 	'UPDATE coel_personne '.
304
		   				"SET cp_mot_de_passe = '$mot_de_passe_sha1' ". 
323
		   				"SET cp_mot_de_passe = '$mot_de_passe_sha1' ". 
305
		   				"WHERE cp_login = '$login' ".
324
		   				"WHERE cp_login = '$login' ".
-
 
325
		   				"	AND cp_ce_projet = '$cp_ce_projet' ".
306
		   				"AND cp_mot_de_passe = '$mot_de_passe_md5' ";
326
		   				"	AND cp_mot_de_passe = '$mot_de_passe_md5' ";
307
			// Ajout des données
327
			// Ajout des données
308
			$resultat = $this->bdd->exec($requete);
328
			$resultat = $this->bdd->exec($requete);
309
			if ($resultat === false) {
329
			if ($resultat === false) {
310
				$this->messages[] = "Le mot de passe de l'utilisateur n'a pas été mis à jour car la requête a échouée.";
330
				$this->messages[] = "Le mot de passe de l'utilisateur n'a pas été mis à jour car la requête a échouée.";
311
			}
331
			}
312
		} catch (PDOException $e) {
332
		} catch (PDOException $e) {
313
			$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
333
			$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
314
		}
334
		}
315
	}
335
	}
316
	
336
	
317
	private function mettreAJourUtilisateur($mot_de_passe_sha1, $infos) {
337
	private function mettreAJourUtilisateur($mot_de_passe_sha1, $infos) {
318
		try {
338
		try {
319
		   	$cp_ce_projet = $this->config['coel']['idProjetUtilisateurs'];
339
		   	$cp_ce_projet = $this->config['coel']['idProjetUtilisateurs'];
320
		   	$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom'];
340
		   	$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom'];
321
			$requete = 	'UPDATE coel_personne '.
341
			$requete = 	'UPDATE coel_personne '.
322
		   				"SET cp_id_personne = '{$infos['id']}', cp_ce_projet = '$cp_ce_projet', ".
342
		   				"SET cp_id_personne = '{$infos['id']}', ".
323
						"	cp_fmt_nom_complet = '$cp_fmt_nom_complet', cp_prenom = '{$infos['prenom']}', cp_nom = '{$infos['nom']}', ".
343
						"	cp_fmt_nom_complet = '$cp_fmt_nom_complet', cp_prenom = '{$infos['prenom']}', cp_nom = '{$infos['nom']}', ".
324
						"	cp_code_postal = '{$infos['code_postal']}', cp_ville = '{$infos['ville']}', cp_truk_courriel = '{$infos['courriel']}', ".
344
						"	cp_code_postal = '{$infos['code_postal']}', cp_ville = '{$infos['ville']}', cp_truk_courriel = '{$infos['courriel']}', ".
325
						"	cp_login = '{$infos['courriel']}', cp_mot_de_passe = '$mot_de_passe_sha1', cp_ce_annuaire = '{$infos['id']}' ".
345
						"	cp_login = '{$infos['courriel']}', cp_mot_de_passe = '$mot_de_passe_sha1', cp_ce_annuaire = '{$infos['id']}' ".
326
		   				"WHERE cp_login = '$login' ".
346
		   				"WHERE cp_login = '$login' ".
-
 
347
		   				"	AND cp_ce_projet = '$cp_ce_projet' ".
327
		   				"AND cp_mot_de_passe = '$mot_de_passe_md5' ";
348
		   				"	AND cp_mot_de_passe = '$mot_de_passe_md5' ";
-
 
349
			
328
			// Ajout des données
350
			// Ajout des données
329
			$resultat = $this->bdd->exec($requete);
351
			$resultat = $this->bdd->exec($requete);
330
			if ($resultat === false) {
352
			if ($resultat === false) {
331
				$this->messages[] = "L'utilisateur n'a pas été mis à jour car la requête a échouée.";
353
				$this->messages[] = "L'utilisateur n'a pas été mis à jour car la requête a échouée.";
332
			}
354
			}
333
		} catch (PDOException $e) {
355
		} catch (PDOException $e) {
334
			$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
356
			$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
335
		}
357
		}
336
	}
358
	}
337
	
359
	
338
	private function ajouterUtilisateurACoel($infos, $mot_de_passe_sha1) {
360
	private function ajouterUtilisateurACoel($infos, $mot_de_passe_sha1) {
339
		try {
361
		try {
340
			// Construction de la requête d'ajout
362
			// Construction de la requête d'ajout
341
		   	// Notes : pour rester compatibles avec l'annuaire de Tela, les utilisateurs sont ajoutés directement avec l'id
363
		   	// Notes : pour rester compatibles avec l'annuaire de Tela, les utilisateurs sont ajoutés directement avec l'id
342
		   	// de l'annuaire Tela. Dans CoelPersonne, les personnes qui ne sont pas utilisateur sont ajoutés avec un id supérieur à 100 000
364
		   	// de l'annuaire Tela. Dans CoelPersonne, les personnes qui ne sont pas utilisateur sont ajoutés avec un id supérieur à 100 000
343
		   	$cp_ce_projet = $this->config['coel']['idProjetUtilisateurs'];
365
		   	$cp_ce_projet = $this->config['coel']['idProjetUtilisateurs'];
344
		   	$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom'];
366
		   	$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom'];
345
		   	$cp_mark_licence = '0'; 
367
		   	$cp_mark_licence = '0'; 
346
		   	$requete = 	'INSERT INTO coel_personne '.
368
		   	$requete = 	'INSERT INTO coel_personne '.
347
		   				"(cp_id_personne, cp_ce_projet, cp_fmt_nom_complet, cp_prenom, cp_nom, cp_code_postal, 
369
		   				'	(cp_id_personne, cp_ce_projet, cp_fmt_nom_complet, cp_prenom, cp_nom, cp_code_postal, '. 
348
		   				  cp_ville, cp_truk_courriel, cp_login, cp_mot_de_passe, cp_ce_annuaire, cp_mark_licence) ".
370
						'	cp_ville, cp_truk_courriel, cp_login, cp_mot_de_passe, cp_ce_annuaire, cp_mark_licence) '.
349
		   				"VALUES ('{$infos['id']}, '$cp_ce_projet', '$cp_fmt_nom_complet', '{$infos['prenom']}', '{$infos['nom']}',". 
371
		   				"VALUES ('{$infos['id']}', '$cp_ce_projet', '$cp_fmt_nom_complet', '{$infos['prenom']}', '{$infos['nom']}', ". 
350
		   				"'{$infos['code_postal']}', '{$infos['ville']}', '{$infos['courriel']}', '{$infos['courriel']}', '".$mot_de_passe_sha1."',". 
372
		   				"'{$infos['code_postal']}', '{$infos['ville']}', '{$infos['courriel']}', '{$infos['courriel']}', '".$mot_de_passe_sha1."', ". 
351
		   				"'{$infos['id']}', $cp_mark_licence) ";
373
		   				"'{$infos['id']}', $cp_mark_licence) ";
-
 
374
		   	//$this->debug[] = $requete;
352
			// Ajout des données
375
			// Ajout des données
353
			$resultat = $this->bdd->exec($requete);
376
			$resultat = $this->bdd->exec($requete);
354
			if ($resultat === false) {
377
			if ($resultat === false) {
355
				$this->messages[] = "L'utilisateur n'a pas été ajouté dans coel_personne car la requête a échouée.";
378
				$this->debug[] = "Utilisateur NON ajouté dans coel_personne car la requête a échouée.";
-
 
379
			} else {
-
 
380
				$this->debug[] = "Utilisateur ajouté à coel_personne.";
356
			}
381
			}
357
		} catch (PDOException $e) {
382
		} catch (PDOException $e) {
358
			$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
383
			$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
359
		}
384
		}
360
	}
385
	}
361
	
386
	
362
	private function souvenirUtilisateur($login, $mot_de_passe_sha1) {
387
	private function souvenirUtilisateur($login, $mot_de_passe_sha1) {
363
		if ($login == '' && $mot_de_passe_sha1 == '') {
388
		if ($login == '' && $mot_de_passe_sha1 == '') {
364
			return false;
389
			return false;
365
		} else if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_sha1)) {
390
		} else if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_sha1)) {
366
			if ($utilisateur_existant['mot_de_passe'] == $mot_de_passe_sha1) {
391
			if ($utilisateur_existant['mot_de_passe'] == $mot_de_passe_sha1) {
367
				$this->setUtilisateur($utilisateur_existant, $_COOKIE['coel_permanence']);
392
				$this->setUtilisateur($utilisateur_existant, $_COOKIE['coel_permanence']);
368
				return true;
393
				return true;
369
			} else {
394
			} else {
370
				return false; 
395
				return false; 
371
			}
396
			}
372
		}
397
		}
373
	}
398
	}
374
	
399
	
375
	private function obtenirInfosAnnuaire($login)	{
400
	private function obtenirInfosAnnuaire($login)	{
376
		$url_annuaire = $this->config['coel']['urlAnnuaire'];
401
		$url_annuaire = $this->config['coel']['urlAnnuaire'];
377
		$login_annuaire = $this->config['coel']['loginAnnuaire'];
402
		$login_annuaire = $this->config['coel']['loginAnnuaire'];
378
		$mdp_annuaire = $this->config['coel']['mdpAnnuaire'];
403
		$mdp_annuaire = $this->config['coel']['mdpAnnuaire'];
379
				
404
				
380
		$login_b64 = base64_encode($login_annuaire.':'.$mdp_annuaire);
405
		$login_b64 = base64_encode($login_annuaire.':'.$mdp_annuaire);
381
		$url_annuaire .= '/'.$login_b64.'/'.$login;
406
		$url_annuaire .= '/'.$login_b64.'/'.$login;
382
		
407
		
383
		$resultat_annuaire = file_get_contents($url_annuaire);
408
		$resultat_annuaire = file_get_contents($url_annuaire);
384
		$tableau_annuaire = null;
409
		$tableau_annuaire = null;
385
		if ($xml_utilisateur = simplexml_load_string($resultat_annuaire))	{
410
		if ($xml_utilisateur = simplexml_load_string($resultat_annuaire))	{
386
			// La fonction a retourné un objet
411
			// La fonction a retourné un objet
387
			foreach ($xml_utilisateur->children() as $key => $val) {
412
			foreach ($xml_utilisateur->children() as $key => $val) {
388
				if ((string) $val != '') {
413
				if ((string) $val != '') {
389
			  		$tableau_annuaire[$key] = (String) $val;
414
			  		$tableau_annuaire[$key] = (String) $val;
390
				}
415
				}
391
			} 
416
			} 
392
		}
417
		}
393
		return $tableau_annuaire;
418
		return $tableau_annuaire;
394
	}
419
	}
395
	
420
	
396
	private function setInfosAnnuaire($infosAnnuaire)	{
421
	private function setInfosAnnuaire($infosAnnuaire)	{
397
		$_SESSION['coel_infosAnnuaire'] = $infosAnnuaire;
422
		$_SESSION['coel_infosAnnuaire'] = $infosAnnuaire;
398
	}
423
	}
399
	
424
	
400
	private function accepterLicence($utilisateur)	{
425
	private function accepterLicence($login)	{
401
		$sortie = false;
426
		$sortie = false;
-
 
427
		try {
402
		try {
428
			$cp_ce_projet = $this->config['coel']['idProjetUtilisateurs'];
403
			$requete = 	'UPDATE coel_personne '.
429
			$requete = 	'UPDATE coel_personne '.
404
						'SET cp_mark_licence = 1 '.
430
						'SET cp_mark_licence = 1 '.
-
 
431
						"WHERE cp_login = {$this->bdd->quote($login)} ";
405
						"WHERE cp_login = {$this->bdd->quote($utilisateur)} ";
432
						"	AND cp_ce_projet = '$cp_ce_projet' ";
406
			$resultat = $this->bdd->exec($requete);
433
			$resultat = $this->bdd->exec($requete);
407
			if ($resultat === false) {
434
			if ($resultat === false) {
408
				$this->log[] = "La table Personne n'a pas été mise à jour car la requête a échouée.";
435
				$this->debug[] = "La table Personne n'a pas été mise à jour car la requête a échouée.";
-
 
436
			} else {
409
			} else {
437
				$this->debug[] = "Création du cookie licence.";
410
				$_SESSION['coel_utilisateur']['licence'] = '1';
438
				$_SESSION['coel_utilisateur']['licence'] = '1';
411
				$this->setCookiePersistant('coel_licence', $utilisateur['licence']);
439
				$this->setCookiePersistant('coel_licence', '1');
412
				$sortie = true;
440
				$sortie = true;
413
			}
441
			}
414
		} catch (PDOException $e) {
442
		} catch (PDOException $e) {
415
		 	$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
443
		 	$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
416
		}
444
		}
417
		return $sortie;
445
		return $sortie;
418
	}
446
	}
419
}
447
}
420
?>
448
?>