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 |
|
33 |
|
34 |
private $licence_acceptee = false;
|
34 |
private $licence_acceptee = false;
|
35 |
|
35 |
|
36 |
// 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
|
37 |
public function getRessource(){
|
37 |
public function getRessource(){
|
38 |
$this->getElement(array('*','*'));
|
38 |
$this->getElement(array('*','*'));
|
39 |
}
|
39 |
}
|
40 |
|
40 |
|
41 |
public function getElement($param){
|
41 |
public function getElement($param){
|
42 |
$identification = false;
|
42 |
$identification = false;
|
43 |
$info = array();
|
43 |
$info = array();
|
44 |
|
44 |
|
45 |
// 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
|
46 |
if (!isset($param[2]) && (!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))) {
|
47 |
$this->deconnecterUtilisateur();
|
47 |
$this->deconnecterUtilisateur();
|
48 |
}
|
48 |
}
|
49 |
|
49 |
|
50 |
// 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
|
51 |
if (isset($param[2])) {
|
51 |
if (isset($param[2])) {
|
52 |
$this->debug[] = "Licence acceptee";
|
52 |
$this->debug[] = "Licence acceptee";
|
53 |
$this->licence_acceptee = true;
|
53 |
$this->licence_acceptee = true;
|
54 |
// Mise à jour de la licence
|
54 |
// Mise à jour de la licence
|
55 |
if (!$this->accepterLicence($param[0])) {
|
55 |
if (!$this->accepterLicence($param[0])) {
|
56 |
$this->debug[] = "Erreur de mise à jour licence utilisateur";
|
56 |
$this->debug[] = "Erreur de mise à jour licence utilisateur";
|
57 |
}
|
57 |
}
|
58 |
} else if (isset($param[1])) { // Non connecté : vérification
|
58 |
} else if (isset($param[1])) { // Non connecté : vérification
|
59 |
if (!$this->getUtilisateur()) { // Si non identifié
|
59 |
if (!$this->getUtilisateur()) { // Si non identifié
|
60 |
$id = null;
|
60 |
$id = null;
|
61 |
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
|
62 |
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']))) {
|
63 |
$id = $this->getUtilisateurId();
|
63 |
$id = $this->getUtilisateurId();
|
64 |
$identification = true;
|
64 |
$identification = true;
|
65 |
$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());
|
66 |
}
|
66 |
}
|
67 |
} 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
|
68 |
$id = $this->getUtilisateurId();
|
68 |
$id = $this->getUtilisateurId();
|
69 |
$identification = true;
|
69 |
$identification = true;
|
70 |
$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());
|
71 |
}
|
71 |
}
|
72 |
|
72 |
|
73 |
// 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
|
74 |
if (is_null($id)) {
|
74 |
if (is_null($id)) {
|
75 |
$id = session_id();
|
75 |
$id = session_id();
|
76 |
$identification = false;
|
76 |
$identification = false;
|
77 |
$info = array($id, $identification);
|
77 |
$info = array($id, $identification);
|
78 |
}
|
78 |
}
|
79 |
} else { // Déjà identifié
|
79 |
} else { // Déjà identifié
|
80 |
$id = $this->getUtilisateurId();
|
80 |
$id = $this->getUtilisateurId();
|
81 |
$identification = true;
|
81 |
$identification = true;
|
82 |
$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());
|
83 |
}
|
83 |
}
|
84 |
} else { // Déconnexion
|
84 |
} else { // Déconnexion
|
85 |
$this->deconnecterUtilisateur();
|
85 |
$this->deconnecterUtilisateur();
|
86 |
$id = session_id();
|
86 |
$id = session_id();
|
87 |
$identification = false;
|
87 |
$identification = false;
|
88 |
$info = array($id, $identification);
|
88 |
$info = array($id, $identification);
|
89 |
}
|
89 |
}
|
90 |
|
90 |
|
91 |
array_unshift($info, $this->getLicence());
|
91 |
array_unshift($info, $this->getLicence());
|
92 |
|
92 |
|
93 |
// Envoie sur la sortie standard
|
93 |
// Envoie sur la sortie standard
|
94 |
$this->envoyer($info);
|
94 |
$this->envoyer($info);
|
95 |
}
|
95 |
}
|
96 |
|
96 |
|
97 |
private function getUtilisateurId() {
|
97 |
private function getUtilisateurId() {
|
98 |
if ($utilisateur = $this->getUtilisateur()) {
|
98 |
if ($utilisateur = $this->getUtilisateur()) {
|
99 |
return $utilisateur['id'];
|
99 |
return $utilisateur['id'];
|
100 |
} else {
|
100 |
} else {
|
101 |
return '';
|
101 |
return '';
|
102 |
}
|
102 |
}
|
103 |
}
|
103 |
}
|
104 |
|
104 |
|
105 |
private function getUtilisateurLogin() {
|
105 |
private function getUtilisateurLogin() {
|
106 |
if ($utilisateur = $this->getUtilisateur()) {
|
106 |
if ($utilisateur = $this->getUtilisateur()) {
|
107 |
return $utilisateur['login'];
|
107 |
return $utilisateur['login'];
|
108 |
} else {
|
108 |
} else {
|
109 |
return '';
|
109 |
return '';
|
110 |
}
|
110 |
}
|
111 |
}
|
111 |
}
|
112 |
|
112 |
|
113 |
private function getUtilisateurNomComplet() {
|
113 |
private function getUtilisateurNomComplet() {
|
114 |
if ($utilisateur = $this->getUtilisateur()) {
|
114 |
if ($utilisateur = $this->getUtilisateur()) {
|
115 |
return $utilisateur['nom_complet'];
|
115 |
return $utilisateur['nom_complet'];
|
116 |
} else {
|
116 |
} else {
|
117 |
return '';
|
117 |
return '';
|
118 |
}
|
118 |
}
|
119 |
}
|
119 |
}
|
120 |
|
120 |
|
121 |
private function getUtilisateurPrenom() {
|
121 |
private function getUtilisateurPrenom() {
|
122 |
if ($utilisateur = $this->getUtilisateur()) {
|
122 |
if ($utilisateur = $this->getUtilisateur()) {
|
123 |
return $utilisateur['prenom'];
|
123 |
return $utilisateur['prenom'];
|
124 |
} else {
|
124 |
} else {
|
125 |
return '';
|
125 |
return '';
|
126 |
}
|
126 |
}
|
127 |
}
|
127 |
}
|
128 |
|
128 |
|
129 |
private function getUtilisateurNom() {
|
129 |
private function getUtilisateurNom() {
|
130 |
if ($utilisateur = $this->getUtilisateur()) {
|
130 |
if ($utilisateur = $this->getUtilisateur()) {
|
131 |
return $utilisateur['nom'];
|
131 |
return $utilisateur['nom'];
|
132 |
} else {
|
132 |
} else {
|
133 |
return '';
|
133 |
return '';
|
134 |
}
|
134 |
}
|
135 |
}
|
135 |
}
|
136 |
|
136 |
|
137 |
private function getParametre() {
|
137 |
private function getParametre() {
|
138 |
if ($utilisateur = $this->getUtilisateur()) {
|
138 |
if ($utilisateur = $this->getUtilisateur()) {
|
139 |
return $utilisateur['parametre'];
|
139 |
return $utilisateur['parametre'];
|
140 |
} else {
|
140 |
} else {
|
141 |
return '';
|
141 |
return '';
|
142 |
}
|
142 |
}
|
143 |
}
|
143 |
}
|
144 |
|
144 |
|
145 |
private function getLicence() {
|
145 |
private function getLicence() {
|
146 |
if (!empty($_SESSION['coel_utilisateur'])) {
|
146 |
if (!empty($_SESSION['coel_utilisateur'])) {
|
147 |
return (string) $_SESSION['coel_utilisateur']['licence'];
|
147 |
return (string) $_SESSION['coel_utilisateur']['licence'];
|
148 |
} else {
|
148 |
} else {
|
149 |
return '';
|
149 |
return '';
|
150 |
}
|
150 |
}
|
151 |
}
|
151 |
}
|
152 |
|
152 |
|
153 |
private function getInfosAnnuaire() {
|
153 |
private function getInfosAnnuaire() {
|
154 |
if (!empty($_SESSION['coel_infosAnnuaire'])) {
|
154 |
if (!empty($_SESSION['coel_infosAnnuaire'])) {
|
155 |
return $_SESSION['coel_infosAnnuaire'];
|
155 |
return $_SESSION['coel_infosAnnuaire'];
|
156 |
} else {
|
156 |
} else {
|
157 |
return '';
|
157 |
return '';
|
158 |
}
|
158 |
}
|
159 |
}
|
159 |
}
|
160 |
|
160 |
|
161 |
private function deconnecterUtilisateur() {
|
161 |
private function deconnecterUtilisateur() {
|
162 |
$_SESSION['coel_utilisateur'] = '';
|
162 |
$_SESSION['coel_utilisateur'] = '';
|
163 |
$_SESSION['coel_infosAnnuaire'] = '';
|
163 |
$_SESSION['coel_infosAnnuaire'] = '';
|
164 |
$this->supprimerCookie('coel_login');
|
164 |
$this->supprimerCookie('coel_login');
|
165 |
$this->supprimerCookie('coel_mot_de_passe');
|
165 |
$this->supprimerCookie('coel_mot_de_passe');
|
166 |
$this->supprimerCookie('coel_licence');
|
166 |
$this->supprimerCookie('coel_licence');
|
167 |
$this->supprimerCookie('coel_permanence');
|
167 |
$this->supprimerCookie('coel_permanence');
|
168 |
}
|
168 |
}
|
169 |
|
169 |
|
170 |
private function connecterUtilisateur($login, $mot_de_passe, $permanence = 1) {
|
170 |
private function connecterUtilisateur($login, $mot_de_passe, $permanence = 1) {
|
171 |
// 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
|
172 |
$infosAnnuaire = $this->obtenirInfosAnnuaire($login);
|
172 |
$infosAnnuaire = $this->obtenirInfosAnnuaire($login);
|
173 |
$this->setInfosAnnuaire($infosAnnuaire);
|
173 |
$this->setInfosAnnuaire($infosAnnuaire);
|
174 |
|
174 |
|
175 |
if ($mot_de_passe == 'debug' && $utilisateur_existant = $this->chargerUtilisateur($login)) {
|
175 |
if ($mot_de_passe == 'debug' && $utilisateur_existant = $this->chargerUtilisateur($login)) {
|
176 |
$this->setUtilisateur($utilisateur_existant, $permanence);
|
176 |
$this->setUtilisateur($utilisateur_existant, $permanence);
|
177 |
return true;
|
177 |
return true;
|
178 |
} else {
|
178 |
} else {
|
179 |
$mot_de_passe_sha1 = sha1($mot_de_passe);
|
179 |
$mot_de_passe_sha1 = sha1($mot_de_passe);
|
180 |
$mot_de_passe_md5 = md5($mot_de_passe);
|
180 |
$mot_de_passe_md5 = md5($mot_de_passe);
|
181 |
if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_sha1)) {
|
181 |
if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_sha1)) {
|
182 |
// OK, nous poursuivons
|
182 |
// OK, nous poursuivons
|
183 |
} else if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_md5)) {
|
183 |
} else if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_md5)) {
|
184 |
// Mise à jour du mot de passe md5 en sha1
|
184 |
// Mise à jour du mot de passe md5 en sha1
|
185 |
$this->mettreAJourMotDePasse($login, $mot_de_passe_md5, $mot_de_passe_sha1);
|
185 |
$this->mettreAJourMotDePasse($login, $mot_de_passe_md5, $mot_de_passe_sha1);
|
186 |
$utilisateur_existant['mot_de_passe'] = $mot_de_passe_sha1;
|
186 |
$utilisateur_existant['mot_de_passe'] = $mot_de_passe_sha1;
|
187 |
}
|
187 |
}
|
188 |
|
188 |
|
189 |
// 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
|
190 |
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";
|
191 |
$this->debug[] = "Besoin d'une mise à jour";
|
192 |
// Vérifions que la personne s'est bien identifiée
|
192 |
// Vérifions que la personne s'est bien identifiée
|
193 |
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";
|
194 |
$this->debug[] = "Identification correcte avec md5";
|
195 |
$utilisateur_existant = $this->getInfoAnnuaireCoelDepuisInfoAnnuaireDistant($mot_de_passe_sha1, $infosAnnuaire);
|
195 |
$utilisateur_existant = $this->getInfoAnnuaireCoelDepuisInfoAnnuaireDistant($mot_de_passe_sha1, $infosAnnuaire);
|
196 |
|
196 |
|
197 |
$presence_dans_coel = $this->verifierPresenceUtilisateur($infosAnnuaire['id']);
|
197 |
$presence_dans_coel = $this->verifierPresenceUtilisateur($infosAnnuaire['id']);
|
198 |
$this->debug[] = "Presence:$presence_dans_coel";
|
198 |
$this->debug[] = "Presence:$presence_dans_coel";
|
199 |
if ($presence_dans_coel) {
|
199 |
if ($presence_dans_coel) {
|
200 |
// 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']}";
|
201 |
$this->debug[] = "Mise à jour de l'utilisateur {$infosAnnuaire['id']}";
|
202 |
$this->mettreAJourUtilisateur($login, $mot_de_passe_sha1, $infosAnnuaire);
|
202 |
$this->mettreAJourUtilisateur($login, $mot_de_passe_sha1, $infosAnnuaire);
|
203 |
$utilisateur_existant['licence'] = (int) $this->recupererLicenceUtilisateur($infosAnnuaire['id']);
|
203 |
$utilisateur_existant['licence'] = (int) $this->recupererLicenceUtilisateur($infosAnnuaire['id']);
|
204 |
} else {
|
204 |
} else {
|
205 |
// Nécessite d'ajouter le nouvel utilisateur
|
205 |
// Nécessite d'ajouter le nouvel utilisateur
|
206 |
$this->debug[] = "Ajout d'une nouvel utilisateur";
|
206 |
$this->debug[] = "Ajout d'une nouvel utilisateur";
|
207 |
$this->ajouterUtilisateurACoel($infosAnnuaire, $mot_de_passe_sha1);
|
207 |
$this->ajouterUtilisateurACoel($infosAnnuaire, $mot_de_passe_sha1);
|
208 |
}
|
208 |
}
|
209 |
|
209 |
|
210 |
$this->setUtilisateur($utilisateur_existant, $permanence);
|
210 |
$this->setUtilisateur($utilisateur_existant, $permanence);
|
211 |
} else {
|
211 |
} else {
|
212 |
$this->debug[] = "Identification INCORRECTE avec md5";
|
212 |
$this->debug[] = "Identification INCORRECTE avec md5";
|
213 |
return false;
|
213 |
return false;
|
214 |
}
|
214 |
}
|
215 |
} else if ($utilisateur_existant != false) {
|
215 |
} else if ($utilisateur_existant != false) {
|
216 |
// 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
|
217 |
$this->setUtilisateur($utilisateur_existant, $permanence);
|
217 |
$this->setUtilisateur($utilisateur_existant, $permanence);
|
218 |
} else {
|
218 |
} else {
|
219 |
// 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
|
220 |
return false;
|
220 |
return false;
|
221 |
}
|
221 |
}
|
222 |
|
222 |
|
223 |
// 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é!
|
224 |
if ($utilisateur_existant['licence'] == 1) {
|
224 |
if ($utilisateur_existant['licence'] == 1) {
|
225 |
return true;
|
225 |
return true;
|
226 |
} else {
|
226 |
} else {
|
227 |
return false;
|
227 |
return false;
|
228 |
}
|
228 |
}
|
229 |
}
|
229 |
}
|
230 |
}
|
230 |
}
|
231 |
|
231 |
|
232 |
private function avoirBesoinMiseAJour($info_annuaire_coel) {
|
232 |
private function avoirBesoinMiseAJour($info_annuaire_coel) {
|
233 |
$necessite_maj = false;
|
233 |
$necessite_maj = false;
|
234 |
if ($info_annuaire_coel == false) {
|
234 |
if ($info_annuaire_coel == false) {
|
235 |
// Le login et/ou le mot de passe a pu changer
|
235 |
// Le login et/ou le mot de passe a pu changer
|
236 |
$necessite_maj = true;
|
236 |
$necessite_maj = true;
|
237 |
} else {
|
237 |
} else {
|
238 |
$info_annuaire_distant = $this->getInfosAnnuaire();
|
238 |
$info_annuaire_distant = $this->getInfosAnnuaire();
|
239 |
if ($this->comparerInfosAnnuairesDistantEtCoel($info_annuaire_distant, $info_annuaire_coel) == false) {
|
239 |
if ($this->comparerInfosAnnuairesDistantEtCoel($info_annuaire_distant, $info_annuaire_coel) == false) {
|
240 |
$necessite_maj = true;
|
240 |
$necessite_maj = true;
|
241 |
}
|
241 |
}
|
242 |
}
|
242 |
}
|
243 |
return $necessite_maj;
|
243 |
return $necessite_maj;
|
244 |
}
|
244 |
}
|
245 |
|
245 |
|
246 |
private function comparerInfosAnnuairesDistantEtCoel($annuaire_distant, $annuaire_coel) {
|
246 |
private function comparerInfosAnnuairesDistantEtCoel($annuaire_distant, $annuaire_coel) {
|
247 |
$identique = true;
|
247 |
$identique = true;
|
248 |
$tableau_annuaire_distant = array('nom' => $annuaire_distant['nom'],
|
248 |
$tableau_annuaire_distant = array('nom' => $annuaire_distant['nom'],
|
249 |
'prenom' => $annuaire_distant['prenom'],
|
249 |
'prenom' => $annuaire_distant['prenom'],
|
250 |
'ville' => $annuaire_distant['ville'],
|
250 |
'ville' => $annuaire_distant['ville'],
|
251 |
'code_postal' => $annuaire_distant['code_postal']);
|
251 |
'code_postal' => $annuaire_distant['code_postal']);
|
252 |
$tableau_annuaire_coel = array('nom' => $annuaire_coel['nom'],
|
252 |
$tableau_annuaire_coel = array('nom' => $annuaire_coel['nom'],
|
253 |
'prenom' => $annuaire_coel['prenom'],
|
253 |
'prenom' => $annuaire_coel['prenom'],
|
254 |
'ville' => $annuaire_coel['ville'],
|
254 |
'ville' => $annuaire_coel['ville'],
|
255 |
'code_postal' => $annuaire_coel['code_postal']);
|
255 |
'code_postal' => $annuaire_coel['code_postal']);
|
256 |
foreach ($tableau_annuaire_distant as $cle => $valeur) {
|
256 |
foreach ($tableau_annuaire_distant as $cle => $valeur) {
|
257 |
if ($tableau_annuaire_coel[$cle] != $valeur) {
|
257 |
if ($tableau_annuaire_coel[$cle] != $valeur) {
|
258 |
$identique = false;
|
258 |
$identique = false;
|
259 |
break;
|
259 |
break;
|
260 |
}
|
260 |
}
|
261 |
}
|
261 |
}
|
262 |
return $identique;
|
262 |
return $identique;
|
263 |
}
|
263 |
}
|
264 |
|
264 |
|
265 |
private function getInfoAnnuaireCoelDepuisInfoAnnuaireDistant($mot_de_passe_sha1, $infos) {
|
265 |
private function getInfoAnnuaireCoelDepuisInfoAnnuaireDistant($mot_de_passe_sha1, $infos) {
|
266 |
$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom'];
|
266 |
$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom'];
|
267 |
$utilisateur_existant = array('id' => $infos['id'], 'login' => $infos['courriel'],
|
267 |
$utilisateur_existant = array('id' => $infos['id'], 'login' => $infos['courriel'],
|
268 |
'mot_de_passe' => $mot_de_passe_sha1,
|
268 |
'mot_de_passe' => $mot_de_passe_sha1,
|
269 |
'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'],
|
270 |
'parametre' => '', 'licence' => '0');
|
270 |
'parametre' => '', 'licence' => '0');
|
271 |
return $utilisateur_existant;
|
271 |
return $utilisateur_existant;
|
272 |
}
|
272 |
}
|
273 |
|
273 |
|
274 |
private function verifierPresenceUtilisateur($id) {
|
274 |
private function verifierPresenceUtilisateur($id) {
|
275 |
$present = false;
|
275 |
$present = false;
|
276 |
$requete = 'SELECT COUNT(cp_id_personne) AS nbre '.
|
276 |
$requete = 'SELECT COUNT(cp_id_personne) AS nbre '.
|
277 |
'FROM coel_personne '.
|
277 |
'FROM coel_personne '.
|
278 |
"WHERE cp_ce_annuaire = {$this->bdd->quote($id)} ".
|
278 |
"WHERE cp_ce_annuaire = {$this->bdd->quote($id)} ".
|
279 |
" AND cp_ce_annuaire = cp_id_personne ";
|
279 |
" AND cp_ce_annuaire = cp_id_personne ";
|
280 |
try {
|
280 |
try {
|
281 |
$nbre = $this->bdd->query($requete)->fetchColumn();
|
281 |
$nbre = $this->bdd->query($requete)->fetchColumn();
|
282 |
if (0 == $nbre) {
|
282 |
if (0 == $nbre) {
|
283 |
$this->debug[] = "Utilisateur NON présent dans l'annuaire de COEL.";
|
283 |
$this->debug[] = "Utilisateur NON présent dans l'annuaire de COEL.";
|
284 |
} else if (1 == $nbre) {
|
284 |
} else if (1 == $nbre) {
|
285 |
$this->debug[] = "Utilisateur présent dans l'annuaire de COEL.";
|
285 |
$this->debug[] = "Utilisateur présent dans l'annuaire de COEL.";
|
286 |
$present = true;
|
286 |
$present = true;
|
287 |
} else if (false === $nbre) {
|
287 |
} else if (false === $nbre) {
|
288 |
$this->debug[] = "Erreur dans la requête de vérification de présence dans l'annuaire de COEL.";
|
288 |
$this->debug[] = "Erreur dans la requête de vérification de présence dans l'annuaire de COEL.";
|
289 |
}
|
289 |
}
|
290 |
} catch (PDOException $e) {
|
290 |
} catch (PDOException $e) {
|
291 |
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
|
291 |
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
|
292 |
}
|
292 |
}
|
293 |
|
293 |
|
294 |
return $present;
|
294 |
return $present;
|
295 |
}
|
295 |
}
|
296 |
|
296 |
|
297 |
private function recupererLicenceUtilisateur($id) {
|
297 |
private function recupererLicenceUtilisateur($id) {
|
298 |
$requete = 'SELECT cp_mark_licence '.
|
298 |
$requete = 'SELECT cp_mark_licence '.
|
299 |
'FROM coel_personne '.
|
299 |
'FROM coel_personne '.
|
300 |
"WHERE cp_ce_annuaire = {$this->bdd->quote($id)} ".
|
300 |
"WHERE cp_ce_annuaire = {$this->bdd->quote($id)} ".
|
301 |
" AND cp_ce_annuaire = cp_id_personne ";
|
301 |
" AND cp_ce_annuaire = cp_id_personne ";
|
302 |
try {
|
302 |
try {
|
303 |
$licence = $this->bdd->query($requete)->fetchColumn();
|
303 |
$licence = $this->bdd->query($requete)->fetchColumn();
|
304 |
if ($licence === false) {
|
304 |
if ($licence === false) {
|
305 |
$this->debug[] = "La licence n'a pas pu être récupérée.";
|
305 |
$this->debug[] = "La licence n'a pas pu être récupérée.";
|
306 |
return 0;
|
306 |
return 0;
|
307 |
} else {
|
307 |
} else {
|
308 |
return $licence;
|
308 |
return $licence;
|
309 |
}
|
309 |
}
|
310 |
} catch (PDOException $e) {
|
310 |
} catch (PDOException $e) {
|
311 |
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
|
311 |
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
|
312 |
}
|
312 |
}
|
313 |
}
|
313 |
}
|
314 |
|
314 |
|
315 |
private function mettreAJourMotDePasse($login, $mot_de_passe_md5, $mot_de_passe_sha1) {
|
315 |
private function mettreAJourMotDePasse($login, $mot_de_passe_md5, $mot_de_passe_sha1) {
|
316 |
try {
|
316 |
try {
|
317 |
$requete = 'UPDATE coel_personne '.
|
317 |
$requete = 'UPDATE coel_personne '.
|
318 |
"SET cp_mot_de_passe = '$mot_de_passe_sha1' ".
|
318 |
"SET cp_mot_de_passe = '$mot_de_passe_sha1' ".
|
319 |
"WHERE cp_login = '$login' ".
|
319 |
"WHERE cp_login = '$login' ".
|
320 |
" AND cp_mot_de_passe = '$mot_de_passe_md5' ";
|
320 |
" AND cp_mot_de_passe = '$mot_de_passe_md5' ";
|
321 |
// Ajout des données
|
321 |
// Ajout des données
|
322 |
$resultat = $this->bdd->exec($requete);
|
322 |
$resultat = $this->bdd->exec($requete);
|
323 |
if ($resultat === false) {
|
323 |
if ($resultat === false) {
|
324 |
$this->messages[] = "Le mot de passe de l'utilisateur n'a pas été mis à jour car la requête a échouée.";
|
324 |
$this->messages[] = "Le mot de passe de l'utilisateur n'a pas été mis à jour car la requête a échouée.";
|
325 |
}
|
325 |
}
|
326 |
} catch (PDOException $e) {
|
326 |
} catch (PDOException $e) {
|
327 |
$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
327 |
$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
328 |
}
|
328 |
}
|
329 |
}
|
329 |
}
|
330 |
|
330 |
|
331 |
private function mettreAJourUtilisateur($login, $mot_de_passe_sha1, $infos) {
|
331 |
private function mettreAJourUtilisateur($login, $mot_de_passe_sha1, $infos) {
|
332 |
try {
|
332 |
try {
|
333 |
$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom'];
|
333 |
$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom'];
|
334 |
$requete = 'UPDATE coel_personne '.
|
334 |
$requete = 'UPDATE coel_personne '.
|
335 |
"SET cp_id_personne = '{$infos['id']}', ".
|
335 |
"SET cp_id_personne = '{$infos['id']}', ".
|
336 |
" cp_fmt_nom_complet = '$cp_fmt_nom_complet', cp_prenom = '{$infos['prenom']}', cp_nom = '{$infos['nom']}', ".
|
336 |
" cp_fmt_nom_complet = '$cp_fmt_nom_complet', cp_prenom = '{$infos['prenom']}', cp_nom = '{$infos['nom']}', ".
|
337 |
" cp_code_postal = '{$infos['code_postal']}', cp_ville = '{$infos['ville']}', cp_truk_courriel = '{$infos['courriel']}', ".
|
337 |
" cp_code_postal = '{$infos['code_postal']}', cp_ville = '{$infos['ville']}', cp_truk_courriel = '{$infos['courriel']}', ".
|
338 |
" cp_login = '{$infos['courriel']}', cp_mot_de_passe = '$mot_de_passe_sha1', cp_ce_annuaire = '{$infos['id']}' ".
|
338 |
" cp_login = '{$infos['courriel']}', cp_mot_de_passe = '$mot_de_passe_sha1', cp_ce_annuaire = '{$infos['id']}' ".
|
339 |
"WHERE cp_login = '$login' ".
|
339 |
"WHERE cp_login = '$login' ".
|
340 |
" AND cp_mot_de_passe = '{$infos['mot_de_passe']}' ";
|
340 |
" AND cp_mot_de_passe = '{$infos['mot_de_passe']}' ";
|
341 |
|
341 |
|
342 |
// Ajout des données
|
342 |
// Ajout des données
|
343 |
$resultat = $this->bdd->exec($requete);
|
343 |
$resultat = $this->bdd->exec($requete);
|
344 |
if ($resultat === false) {
|
344 |
if ($resultat === false) {
|
345 |
$this->messages[] = "L'utilisateur n'a pas été mis à jour car la requête a échouée.";
|
345 |
$this->messages[] = "L'utilisateur n'a pas été mis à jour car la requête a échouée.";
|
346 |
}
|
346 |
}
|
347 |
} catch (PDOException $e) {
|
347 |
} catch (PDOException $e) {
|
348 |
$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
348 |
$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
349 |
}
|
349 |
}
|
350 |
}
|
350 |
}
|
351 |
|
351 |
|
352 |
private function ajouterUtilisateurACoel($infos, $mot_de_passe_sha1) {
|
352 |
private function ajouterUtilisateurACoel($infos, $mot_de_passe_sha1) {
|
353 |
try {
|
353 |
try {
|
354 |
// Construction de la requête d'ajout
|
354 |
// Construction de la requête d'ajout
|
355 |
// Notes : pour rester compatibles avec l'annuaire de Tela, les utilisateurs sont ajoutés directement avec l'id
|
355 |
// Notes : pour rester compatibles avec l'annuaire de Tela, les utilisateurs sont ajoutés directement avec l'id
|
356 |
// de l'annuaire Tela. Dans CoelPersonne, les personnes qui ne sont pas utilisateur sont ajoutés avec un id supérieur à 100 000
|
356 |
// de l'annuaire Tela. Dans CoelPersonne, les personnes qui ne sont pas utilisateur sont ajoutés avec un id supérieur à 100 000
|
357 |
$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom'];
|
357 |
$cp_fmt_nom_complet = $infos['prenom'].' '.$infos['nom'];
|
358 |
$cp_mark_licence = '0';
|
358 |
$cp_mark_licence = '0';
|
359 |
$requete = 'INSERT INTO coel_personne '.
|
359 |
$requete = 'INSERT INTO coel_personne '.
|
360 |
' (cp_id_personne, cp_fmt_nom_complet, cp_prenom, cp_nom, cp_code_postal, '.
|
360 |
' (cp_id_personne, cp_fmt_nom_complet, cp_prenom, cp_nom, cp_code_postal, '.
|
361 |
' cp_ville, cp_truk_courriel, cp_login, cp_mot_de_passe, cp_ce_annuaire, cp_mark_licence) '.
|
361 |
' cp_ville, cp_truk_courriel, cp_login, cp_mot_de_passe, cp_ce_annuaire, cp_mark_licence) '.
|
362 |
"VALUES ('{$infos['id']}', '$cp_fmt_nom_complet', '{$infos['prenom']}', '{$infos['nom']}', ".
|
362 |
"VALUES ('{$infos['id']}', '$cp_fmt_nom_complet', '{$infos['prenom']}', '{$infos['nom']}', ".
|
363 |
"'{$infos['code_postal']}', '{$infos['ville']}', '{$infos['courriel']}', '{$infos['courriel']}', '".$mot_de_passe_sha1."', ".
|
363 |
"'{$infos['code_postal']}', '{$infos['ville']}', '{$infos['courriel']}', '{$infos['courriel']}', '".$mot_de_passe_sha1."', ".
|
364 |
"'{$infos['id']}', $cp_mark_licence) ";
|
364 |
"'{$infos['id']}', $cp_mark_licence) ";
|
365 |
//$this->debug[] = $requete;
|
365 |
//$this->debug[] = $requete;
|
366 |
// Ajout des données
|
366 |
// Ajout des données
|
367 |
$resultat = $this->bdd->exec($requete);
|
367 |
$resultat = $this->bdd->exec($requete);
|
368 |
if ($resultat === false) {
|
368 |
if ($resultat === false) {
|
369 |
$this->debug[] = "Utilisateur NON ajouté dans coel_personne car la requête a échouée.";
|
369 |
$this->debug[] = "Utilisateur NON ajouté dans coel_personne car la requête a échouée.";
|
370 |
} else {
|
370 |
} else {
|
371 |
$this->debug[] = "Utilisateur ajouté à coel_personne.";
|
371 |
$this->debug[] = "Utilisateur ajouté à coel_personne.";
|
372 |
}
|
372 |
}
|
373 |
} catch (PDOException $e) {
|
373 |
} catch (PDOException $e) {
|
374 |
$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
374 |
$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
375 |
}
|
375 |
}
|
376 |
}
|
376 |
}
|
377 |
|
377 |
|
378 |
private function souvenirUtilisateur($login, $mot_de_passe_sha1) {
|
378 |
private function souvenirUtilisateur($login, $mot_de_passe_sha1) {
|
379 |
if ($login == '' && $mot_de_passe_sha1 == '') {
|
379 |
if ($login == '' && $mot_de_passe_sha1 == '') {
|
380 |
return false;
|
380 |
return false;
|
381 |
} else if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_sha1)) {
|
381 |
} else if ($utilisateur_existant = $this->chargerUtilisateur($login, $mot_de_passe_sha1)) {
|
382 |
if ($utilisateur_existant['mot_de_passe'] == $mot_de_passe_sha1) {
|
382 |
if ($utilisateur_existant['mot_de_passe'] == $mot_de_passe_sha1) {
|
383 |
$this->setUtilisateur($utilisateur_existant, $_COOKIE['coel_permanence']);
|
383 |
$this->setUtilisateur($utilisateur_existant, $_COOKIE['coel_permanence']);
|
384 |
return true;
|
384 |
return true;
|
385 |
} else {
|
385 |
} else {
|
386 |
return false;
|
386 |
return false;
|
387 |
}
|
387 |
}
|
388 |
}
|
388 |
}
|
389 |
}
|
389 |
}
|
390 |
|
390 |
|
391 |
private function obtenirInfosAnnuaire($login) {
|
391 |
private function obtenirInfosAnnuaire($login) {
|
392 |
$url_annuaire = $this->config['coel']['urlAnnuaire'];
|
392 |
$url_annuaire = $this->config['coel']['urlAnnuaire'];
|
393 |
$login_annuaire = $this->config['coel']['loginAnnuaire'];
|
393 |
$login_annuaire = $this->config['coel']['loginAnnuaire'];
|
394 |
$mdp_annuaire = $this->config['coel']['mdpAnnuaire'];
|
394 |
$mdp_annuaire = $this->config['coel']['mdpAnnuaire'];
|
395 |
|
395 |
|
- |
|
396 |
$posds = strpos($url_annuaire, "//");
|
- |
|
397 |
$protocole = substr($url_annuaire, 0, $posds+2);
|
- |
|
398 |
$reste_adresse = substr($url_annuaire, $posds+2);
|
- |
|
399 |
// auth HTTP basic cracra
|
396 |
$login_b64 = base64_encode($login_annuaire.':'.$mdp_annuaire);
|
400 |
$url_annuaire = $protocole . $login_annuaire . ':' . $mdp_annuaire . "@" . $reste_adresse;
|
397 |
$url_annuaire .= '/'.$login_b64.'/'.$login;
|
401 |
$url_annuaire .= '/' . $login;
|
- |
|
402 |
$url_annuaire .= '/xml'; // @TODO un jour, faire en sorte que ça lise du JSON
|
398 |
|
403 |
|
399 |
$resultat_annuaire = file_get_contents($url_annuaire);
|
404 |
$resultat_annuaire = file_get_contents($url_annuaire);
|
400 |
$tableau_annuaire = null;
|
405 |
$tableau_annuaire = null;
|
401 |
if ($xml_utilisateur = simplexml_load_string($resultat_annuaire)) {
|
406 |
if ($xml_utilisateur = simplexml_load_string($resultat_annuaire)) {
|
402 |
// La fonction a retourné un objet
|
407 |
// La fonction a retourné un objet
|
403 |
foreach ($xml_utilisateur->children() as $key => $val) {
|
408 |
foreach ($xml_utilisateur->children() as $key => $val) {
|
404 |
if ((string) $val != '') {
|
409 |
if ((string) $val != '') {
|
405 |
$tableau_annuaire[$key] = (String) $val;
|
410 |
$tableau_annuaire[$key] = (String) $val;
|
406 |
}
|
411 |
}
|
407 |
}
|
412 |
}
|
408 |
}
|
413 |
}
|
409 |
return $tableau_annuaire;
|
414 |
return $tableau_annuaire;
|
410 |
}
|
415 |
}
|
411 |
|
416 |
|
412 |
private function setInfosAnnuaire($infosAnnuaire) {
|
417 |
private function setInfosAnnuaire($infosAnnuaire) {
|
413 |
$_SESSION['coel_infosAnnuaire'] = $infosAnnuaire;
|
418 |
$_SESSION['coel_infosAnnuaire'] = $infosAnnuaire;
|
414 |
}
|
419 |
}
|
415 |
|
420 |
|
416 |
private function accepterLicence($login) {
|
421 |
private function accepterLicence($login) {
|
417 |
$sortie = false;
|
422 |
$sortie = false;
|
418 |
try {
|
423 |
try {
|
419 |
$requete = 'UPDATE coel_personne '.
|
424 |
$requete = 'UPDATE coel_personne '.
|
420 |
'SET cp_mark_licence = 1 '.
|
425 |
'SET cp_mark_licence = 1 '.
|
421 |
"WHERE cp_login = {$this->bdd->quote($login)} ";
|
426 |
"WHERE cp_login = {$this->bdd->quote($login)} ";
|
422 |
$resultat = $this->bdd->exec($requete);
|
427 |
$resultat = $this->bdd->exec($requete);
|
423 |
if ($resultat === false) {
|
428 |
if ($resultat === false) {
|
424 |
$this->debug[] = "La table Personne n'a pas été mise à jour car la requête a échouée.";
|
429 |
$this->debug[] = "La table Personne n'a pas été mise à jour car la requête a échouée.";
|
425 |
} else {
|
430 |
} else {
|
426 |
$this->debug[] = "Création du cookie licence.";
|
431 |
$this->debug[] = "Création du cookie licence.";
|
427 |
$_SESSION['coel_utilisateur']['licence'] = '1';
|
432 |
$_SESSION['coel_utilisateur']['licence'] = '1';
|
428 |
$this->setCookiePersistant('coel_licence', '1');
|
433 |
$this->setCookiePersistant('coel_licence', '1');
|
429 |
$sortie = true;
|
434 |
$sortie = true;
|
430 |
}
|
435 |
}
|
431 |
} catch (PDOException $e) {
|
436 |
} catch (PDOException $e) {
|
432 |
$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
437 |
$messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
433 |
}
|
438 |
}
|
434 |
return $sortie;
|
439 |
return $sortie;
|
435 |
}
|
440 |
}
|
436 |
}
|
441 |
}
|
437 |
?>
|
442 |
?>
|