/**
  * 
  * @param array $cokies
  * @param PCModelApplication $application
  * @return boolean
  */
 public function autorizeWithCookies($cokies, $application, &$user_reference)
 {
     if (isset($_SESSION['user'])) {
         if (!isset($cokies["presence_c"]) || !isset($cokies["user"])) {
             unset($_SESSION['user']);
             return FALSE;
         }
         $user_identifier = $_SESSION['user'];
         PCModelUser::setCurrentUserID($user_identifier);
         $this->user_id = $user_identifier;
         $user_reference = $user_identifier;
         return TRUE;
     } else {
         if (isset($cokies["presence_c"]) && isset($cokies["user"])) {
             $presence = $cokies["presence_c"];
             $user = $cokies["user"];
             $token = PCModelManager::fetchModelObjectInstances(PCModelToken::getMapper(), array("user_id" => $user, "app_id" => $application->getAppId()), NULL, TRUE);
             $count = count($token);
             if ($count > 0) {
                 $aToken = $token[0];
                 if (strcmp($aToken->getTokenStringValue(), $presence) == 0) {
                     $_SESSION['user'] = $user;
                     $this->user_id = $user;
                     $user_reference = $user;
                     PCModelUser::setCurrentUserID($user);
                     return TRUE;
                 }
             }
             $response = PCResponse::currentResponse();
             $response->addCookie(PCResponseCookie::expiredCookie("user"));
             $response->addCookie(PCResponseCookie::expiredCookie("presence_c"));
         }
     }
     return FALSE;
 }
Example #2
0
 /**
  * Elimina il token relativo ad un certo utente e applicazione
  * @param string $user_id l'id dell' utente
  * @param string $app_id l'id dell' app
  * @return boolean
  */
 
 public static function removeTokenForUser($user_id, $app_id){
     
     $conditions = "user_identifier = :user AND 	app_identifier = :app";
     $bindings = array(":user" => $user_id, ":app"=> $app_id );
     
     return PCModelManager::deleteObject(PCModelToken::getMapper(), $conditions, $bindings);
 }