/** * 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); }
/** * * @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; }
/** * * @param string $email * @param PCModelUser $userValue * @param string $error * @return string|FALSE */ public static function createRepassRequest($email, &$userValue, &$error){ if(PCMapperUser::validateMail($email) == FALSE){ $error = "Please insert a valid email1"; return FALSE; } $users = PCModelManager::fetchModelObjectInstances(PCModelUser::getMapper(), array('email' => $email), NULL, TRUE); if(count($users) == 0){ $error = "Please insert a valid email"; return FALSE; } $user = $users[0]; $userValue = $user; $token = PCModelToken::generateToken(); $expirationDate = new DateTime("now",new DateTimeZone('UTC')); $expirationDate->add(new DateInterval("PT20M")); $expiration_mysql_format = $expirationDate->format('Y-m-d H:i:s'); $values = array('expiration_date' => $expiration_mysql_format, "user_id" => $user->getIdentifier(), 'request_hash' => $token); $result = PCModelManager::insertObject(PCModelRepass::getMapper(), $values, array('expiration_date')); if($result === FALSE){ $error = "Please insert a valid email"; return FALSE; } return $token; }