281 |
aurelien |
1 |
<?php
|
|
|
2 |
//+----------------------------------------------------------------------------------------------------------------+
|
|
|
3 |
// GESTION DE L'IDENTIFICATION
|
|
|
4 |
Class ControleUtilisateur extends JRestService {
|
|
|
5 |
|
|
|
6 |
private function envoyerAuth($message_accueil, $message_echec) {
|
|
|
7 |
header('HTTP/1.0 401 Unauthorized');
|
|
|
8 |
header('WWW-Authenticate: Basic realm="UTF-8"');
|
|
|
9 |
header('Content-type: text/plain; charset=UTF-8');
|
|
|
10 |
print $message_echec;
|
|
|
11 |
exit(0);
|
|
|
12 |
}
|
|
|
13 |
|
|
|
14 |
protected function getAuthIdentifiant() {
|
|
|
15 |
$id = (isset($_SERVER['PHP_AUTH_USER'])) ? $_SERVER['PHP_AUTH_USER'] : null;
|
|
|
16 |
return $id;
|
|
|
17 |
}
|
|
|
18 |
|
|
|
19 |
protected function getAuthMotDePasse() {
|
|
|
20 |
$mdp = (isset($_SERVER['PHP_AUTH_PW'])) ? $_SERVER['PHP_AUTH_PW'] : null;
|
|
|
21 |
return $mdp;
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
public function authentifierAdmin() {
|
|
|
25 |
$message_accueil = "Veuillez vous identifier avec votre compte Observatoire des saisons.";
|
|
|
26 |
$message_echec = "Accès limité aux administrateurs de l'ods.\n".
|
|
|
27 |
"Votre tentative d'identification a échoué.\n".
|
|
|
28 |
"Actualiser la page pour essayer à nouveau si vous êtes bien inscrit comme administrateur.";
|
|
|
29 |
return $this->authentifier($message_accueil, $message_echec, 'Admin');
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
private function authentifier($message_accueil, $message_echec, $type) {
|
|
|
33 |
$id = $this->getAuthIdentifiant();
|
|
|
34 |
if (!isset($id)) {
|
|
|
35 |
$this->envoyerAuth($message_accueil, $message_echec);
|
|
|
36 |
} else {
|
|
|
37 |
$methodeAutorisation = "etre{$type}Autorise";
|
|
|
38 |
$autorisation = $this->$methodeAutorisation();
|
|
|
39 |
|
|
|
40 |
if ($autorisation == false) {
|
|
|
41 |
$this->envoyerAuth($message_accueil, $message_echec);
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
return true;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public function etreUtilisateurAutorise() {
|
|
|
48 |
$identifiant = $this->getAuthIdentifiant();
|
|
|
49 |
$mdp = md5($this->getAuthMotDePasse());
|
|
|
50 |
|
|
|
51 |
$requete = 'SELECT COUNT(*) as existe FROM ods_redesign.drupal_users du '.
|
|
|
52 |
'WHERE name = '.$this->proteger($identifiant).' '.
|
|
|
53 |
'AND pass = '.$this->proteger($mdp);
|
|
|
54 |
|
|
|
55 |
$existe = $this->executerRequete($requete);
|
|
|
56 |
|
|
|
57 |
$autorisation = (!empty($existe) && $existe['existe'] > 0) ? true :false;
|
|
|
58 |
return $autorisation;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public function etreAdminAutorise() {
|
|
|
62 |
$identifiant = $this->getAuthIdentifiant();
|
|
|
63 |
$mdp = md5($this->getAuthMotDePasse());
|
|
|
64 |
|
|
|
65 |
$requete = 'SELECT COUNT(*) as existe FROM ods_redesign.drupal_users du '.
|
|
|
66 |
'INNER JOIN ods_redesign.drupal_users_roles dur '.
|
|
|
67 |
'ON du.uid = dur.uid '.
|
|
|
68 |
'WHERE name = '.$this->proteger($identifiant).' '.
|
|
|
69 |
'AND pass = '.$this->proteger($mdp).' '.
|
|
|
70 |
'AND rid = 3 ';
|
|
|
71 |
$existe = $this->executerRequete($requete);
|
|
|
72 |
|
|
|
73 |
$autorisation = (!empty($existe) && $existe[0]['existe'] > 0) ? true :false;
|
|
|
74 |
return $autorisation;
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
?>
|