Rev 85 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*** PHP Version 5** @category PHP* @package annuaire* @author aurelien <aurelien@tela-botanica.org>* @copyright 2010 Tela-Botanica* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL* @version SVN: <svn_id>* @link /doc/annuaire/*/Class IdentificationControleur extends Controleur {private $nom_cookie_persistant = '';private $duree_identification = '0';private $fonction_cryptage_mdp_cookie = 'sha1';public function IdentificationControleur() {//$this->cookie_persistant_nom = session_name().'-memo';$this->cookie_persistant_nom = 'pap-admin_papyrus_-memo';$this->duree_identification = time()+Config::get('duree_session_identification');$this->fonction_cryptage_mdp_cookie = Config::get('fonction_cryptage_mdp_cookie');}public function afficherFormulaireIdentification($id_annuaire, $donnees = array()) {$this->chargerModele('AnnuaireModele');$annuaire = $this->AnnuaireModele->chargerAnnuaire($id_annuaire);return $this->getVue(Config::get('dossier_squelettes_formulaires').$annuaire['informations']['aa_code'].'_identification',$donnees);}public function identificationOpenID($identifiant) {// crée une zone de stockage pour les données OpenID$store = new Auth_OpenID_FileStore('./oid_store');// crée un consommateur OpenID$consumer = new Auth_OpenID_Consumer($store);if ($_COOKIE['h_infos'] == null) {// vérifie les valeurs du formulaireif (trim($identifiant == '')) {$_SESSION['id'] = 0 ;die("ERROR: Entrez un OpenID valide svp.");}} else {// dans le cas ou un cookie du site est déjà présent$str_infos_client = $_COOKIE['h_infos'];$infos_client = unserialize(stripslashes($str_infos_client));// on vérifie son contenu et on le compare à ce qui est en coursif ($infos_client['h_browser'] == md5($_SESSION['HTTP_USER_AGENT']) && $infos_client['h_remote_addr'] == md5($_SESSION['REMOTE_ADDR']) && $infos_client['oid_user_name'] != null) {$identifiant = $infos_client['oid_user_name'];$_SESSION['id'] = 1;session_regenerate_id();} else {die("ERROR: Tentative de fixation de session ?");}}// commence le process d'authentification// crée une requête d'authentification pour le fournisseur OpenID$auth = $consumer->begin($_POST['id']);if (!$auth) {die("ERROR: Entrez un OpenID valide svp.");}// si on est arrivé déjà authentifiéif ($infos_client['oid_user_name'] != null) {// on fait une redirection immédiate$url = $auth->redirectURL('http://162.38.234.9/', 'http://162.38.234.9/annuaire.php',true);} else {// sinon on crée un cookie et on appelle openId pour s'autentifier$_SESSION['id'] = 1;$this->fabriquerCookie($identifiant);$url = $auth->redirectURL('http://162.38.234.9/', 'http://162.38.234.9/OpenId1/annuaire.php');}// redirige vers le fournisseur OpenID pour l'authentificationheader('Location: ' . $url);}private function fabriquerCookieOpenId($identifiant) {$infos_client = array('h_browser' => md5($_SESSION['HTTP_USER_AGENT']),'h_remote_addr' => md5($_SESSION['REMOTE_ADDR']),'oid_user_name' => $identifiant);$str_infos_client = serialize($infos_client);setCookie('h_infos',$str_infos_client,0,'/','162.38.234.9');}public function fabriquerCookie($utilisateur, $mot_de_passe, $crypter_mot_de_passe = true) {if($crypter_mot_de_passe) {if(function_exists($this->fonction_cryptage_mdp_cookie)) {$fonction_cryptage = $this->fonction_cryptage_mdp_cookie;$mot_de_passe_crypte = $fonction_cryptage($mot_de_passe);} else {$mot_de_passe_crypte = md5($mot_de_passe);}}// Expiration si l'utilisateur ne referme pas son navigateur$GLOBALS['_GEN_commun']['pear_auth']->setExpire((int)$this->duree_identification);// Création d'un cookie pour rendre permanente l'identification$cookie_val = $mot_de_passe_crypte.$utilisateur;setcookie($this->cookie_persistant_nom, $cookie_val, (int)$this->duree_identification, '/');}public function loggerUtilisateurParCookie() {// Si un cookie existe, nous loggons l'utilisateur.$GLOBALS['_GEN_commun']['pear_auth']->password = substr($_COOKIE[$this->cookie_persistant_nom], 0, 32 );$GLOBALS['_GEN_commun']['pear_auth']->username = substr($_COOKIE[$this->cookie_persistant_nom], 32);// Nous sommes obligés de crypter le mot de passeif (isset($GLOBALS['_GEN_commun']['pear_auth']->storage_options)) {$GLOBALS['_GEN_commun']['pear_auth']->storage_options['cryptType'] = 'none';}if (isset($GLOBALS['_GEN_commun']['pear_auth']->storage->options)) {$GLOBALS['_GEN_commun']['pear_auth']->storage->options['cryptType'] = 'none';}}}?>