Subversion Repositories Applications.annuaire

Rev

Rev 56 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
45 aurelien 1
<?php
2
/**
3
* PHP Version 5
4
*
5
* @category  PHP
6
* @package   annuaire
7
* @author    aurelien <aurelien@tela-botanica.org>
8
* @copyright 2010 Tela-Botanica
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
10
* @version   SVN: <svn_id>
11
* @link      /doc/annuaire/
12
*/
13
 
14
Class IdentificationControleur extends Controleur {
15
 
16
	private $nom_cookie_persistant = '';
17
	private $duree_identification = '0';
18
	private $fonction_cryptage_mdp_cookie = 'sha1';
19
 
20
	public function IdentificationControleur() {
21
		//$this->cookie_persistant_nom = session_name().'-memo';
22
		$this->cookie_persistant_nom = 'pap-admin_papyrus_-memo';
23
		$this->duree_identification = time()+Config::get('duree_session_identification');
24
		$this->fonction_cryptage_mdp_cookie = Config::get('fonction_cryptage_mdp_cookie');
25
	}
26
 
27
	public function afficherFormulaireIdentification($id_annuaire, $donnees = array()) {
28
 
29
		$this->chargerModele('AnnuaireModele');
30
		$annuaire = $this->AnnuaireModele->chargerAnnuaire($id_annuaire);
31
 
32
		return $this->getVue(Config::get('dossier_squelettes_formulaires').$annuaire['informations']['aa_code'].'_identification',$donnees);
33
	}
34
 
35
	public function identificationOpenID($identifiant) {
36
 
37
		// crée une zone de stockage pour les données OpenID
38
	  	$store = new Auth_OpenID_FileStore('./oid_store');
39
 
40
	  	// crée un consommateur OpenID
41
	  	$consumer = new Auth_OpenID_Consumer($store);
42
 
43
		if ($_COOKIE['h_infos'] == null) {
44
		  // vérifie les valeurs du formulaire
45
		  if (trim($identifiant == '')) {
46
		   $_SESSION['id'] = 0 ;
47
		    die("ERROR: Entrez un OpenID valide svp.");
48
		  }
49
		} else {
50
			// dans le cas ou un cookie du site est déjà présent
51
			$str_infos_client = $_COOKIE['h_infos'];
52
			$infos_client = unserialize(stripslashes($str_infos_client));
53
			// on vérifie son contenu et on le compare à ce qui est en cours
54
			if ($infos_client['h_browser'] ==  md5($_SESSION['HTTP_USER_AGENT']) && $infos_client['h_remote_addr'] ==  md5($_SESSION['REMOTE_ADDR']) && $infos_client['oid_user_name'] !=  null) {
55
				$identifiant = $infos_client['oid_user_name'];
56
				$_SESSION['id'] = 1;
57
				session_regenerate_id();
58
			} else {
59
				die("ERROR: Tentative de fixation de session ?");
60
			}
61
		}
62
 
63
	  	// commence le process d'authentification
64
	  	// crée une requête d'authentification pour le fournisseur OpenID
65
	  	$auth = $consumer->begin($_POST['id']);
66
	  	if (!$auth) {
67
			die("ERROR: Entrez un OpenID valide svp.");
68
	  	}
69
 
70
	  	// si on est arrivé déjà authentifié
71
	  	if ($infos_client['oid_user_name'] != null) {
72
		// on fait une redirection immédiate
73
		$url = $auth->redirectURL('http://162.38.234.9/', 'http://162.38.234.9/annuaire.php',true);
74
	  } else {
75
		// sinon on crée un cookie et on appelle openId pour s'autentifier
76
		$_SESSION['id'] = 1;
77
		$this->fabriquerCookie($identifiant);
78
		$url = $auth->redirectURL('http://162.38.234.9/', 'http://162.38.234.9/OpenId1/annuaire.php');
79
	  }
80
	  	// redirige vers le fournisseur OpenID pour l'authentification
81
		header('Location: ' . $url);
82
	}
83
 
84
	private function fabriquerCookieOpenId($identifiant) {
85
 
86
				$infos_client = array('h_browser' => md5($_SESSION['HTTP_USER_AGENT']),
87
						'h_remote_addr' => md5($_SESSION['REMOTE_ADDR']),
88
						'oid_user_name' => $identifiant);
89
		$str_infos_client = serialize($infos_client);
90
		setCookie('h_infos',$str_infos_client,0,'/','162.38.234.9');
91
	}
92
 
93
	public function fabriquerCookie($utilisateur, $mot_de_passe, $crypter_mot_de_passe = true) {
94
 
95
		if($crypter_mot_de_passe) {
96
			if(function_exists($this->fonction_cryptage_mdp_cookie)) {
97
 
98
				$fonction_cryptage = $this->fonction_cryptage_mdp_cookie;
99
 
100
				$mot_de_passe_crypte = $fonction_cryptage($mot_de_passe);
101
			} else {
102
				$mot_de_passe_crypte = md5($mot_de_passe);
103
			}
104
		}
105
 
106
        // Expiration si l'utilisateur ne referme pas son navigateur
107
		$GLOBALS['_GEN_commun']['pear_auth']->setExpire((int)$this->duree_identification);
108
		// Création d'un cookie pour rendre permanente l'identification
109
		$cookie_val = $mot_de_passe_crypte.$utilisateur;
110
		setcookie($this->cookie_persistant_nom, $cookie_val, (int)$this->duree_identification, '/');
111
 
112
	}
113
 
114
	public function loggerUtilisateurParCookie() {
115
 
116
		// Si un cookie existe, nous loggons l'utilisateur.
117
		$GLOBALS['_GEN_commun']['pear_auth']->password = substr($_COOKIE[$this->cookie_persistant_nom], 0, 32 );
118
		$GLOBALS['_GEN_commun']['pear_auth']->username = substr($_COOKIE[$this->cookie_persistant_nom], 32);
119
		// Nous sommes obligés de crypter le mot de passe
120
		if (isset($GLOBALS['_GEN_commun']['pear_auth']->storage_options)) {
121
			$GLOBALS['_GEN_commun']['pear_auth']->storage_options['cryptType'] = 'none';
122
		}
123
		if (isset($GLOBALS['_GEN_commun']['pear_auth']->storage->options)) {
124
			$GLOBALS['_GEN_commun']['pear_auth']->storage->options['cryptType'] = 'none';
125
		}
126
	}
127
}
128
?>