config=$config; } // TODO : controle systematique ....dans tous les services // Si connected : name cookie = name service function getRessource(){ $expireTime = 60*60*24*100; // 100 jours session_set_cookie_params($expireTime); $connected=false; $admin=false; session_start(); if (!$this->GetUser()) { if (isset($_COOKIE["cel_name"]) && ($this->RememberedUser($_COOKIE["cel_name"], $_COOKIE["cel_password"]))) { $retour= $this->GetUserName(); $connected=true; } else { $retour = session_id(); $connected=false; } } else { $retour= $this->GetUserName(); $connected=true; } $admin = $this->isAdmin($retour) ; $output = json_encode(array($retour,$connected,$admin)); print($output); } function getElement($uid){ $connected=false; session_start(); // Non connect� : verification if (isset($uid[1])) { // Identification if (!$this->GetUser()) { // Si non identifi� if ($this->LoginUser($uid[0],$uid[1],1)) { // identification reussi $retour= $this->GetUserName(); $connected=true; } else { $retour = session_id(); $connected=false; } } else { // Deja identifi� $retour= $this->GetUserName(); $connected=true; } } else { // Deconnection $this->LogoutUser(); $retour = session_id(); $connected=false; } $admin = $this->isAdmin($retour) ; $output = json_encode(array($retour,$connected,$admin)); print($output); } // USERS function LoadUser($name) { $password = ; $admin = $this->isAdmin($name) ; $retour= array("name"=>$name,"password"=>$password,"admin"=>$admin); return $retour; } function GetUserName() { if ($user = $this->GetUser()) { $name = $user["name"]; } else { $name =""; } return $name; } function GetUser() { return (isset($_SESSION["user"]) ? $_SESSION["user"] : ''); } function SetUser($user, $remember=1) { $_SESSION["user"] = $user; $this->SetPersistentCookie("cel_name", $user["name"], $remember); $this->SetPersistentCookie("cel_password", $user["password"], $remember); $this->SetPersistentCookie("cel_remember", $remember, $remember); } function LogoutUser() { $_SESSION["user"] = ""; $this->DeleteCookie("cel_name"); $this->DeleteCookie("cel_password"); $this->DeleteCookie("cel_remember"); } function SetPersistentCookie($name, $value, $remember = 1) { SetCookie($name, $value, time() + ($remember ? 90*24*60*60 : 60 * 60),'/'); $_COOKIE[$name] = $value; } function DeleteCookie($name) { SetCookie($name, "", 1,'/'); $_COOKIE[$name] = ""; } function LoginUser($name,$password,$remember=1) { if ($existingUser = $this->LoadUser($name)) { if ($password!="debug") { if ($existingUser["password"] == md5($password)) { $this->SetUser($existingUser, $remember); return true; } else { return false; } } else { $this->SetUser($existingUser, $remember); return true; } } } function RememberedUser($name,$password,$remember=1) { if ($existingUser = $this->LoadUser($name)) { if ($existingUser["password"] == $password) { $this->SetUser($existingUser, $remember); return true; } else { return false; } } } } /* +--Fin du code ---------------------------------------------------------------------------------------+ * $Log$ * Revision 1.5 2008-01-30 08:57:28 ddelon * fin mise en place mygwt * * Revision 1.4 2007-05-22 12:54:09 ddelon * Securisation acces utilisateur * * Revision 1.3 2007-05-21 18:12:20 ddelon * Gestion des importations locale de releves * * */ ?>