Beispiel #1
0
    /**
     * Setta i cookie dell'utente
     * @param PCModelUserOauth $user
     * @return boolean
     */
    private function authorizeUser($user) {
        if(isset($user) === FALSE) return FALSE;
        $_SESSION['user'] = $user->getIdentifier();

        $secret = $this->application->getAppSecret();
        $appId = $this->application->getIdentifier();
        $time = time();
        $cookieValue = PCAuth::computeHashForString($user->getUsername() . $time . $secret);
        $distantFuture = PCResponseCookie::getDistantFuture();

        if (PCMapperToken::setTokenForUserWithIdentifier($user->getIdentifier(), $appId, $cookieValue, $distantFuture)) {

            $_SESSION['user'] = $user->getIdentifier();

            $presence_cookie = PCResponseCookie::lifetimeCookie("presence_c", $cookieValue);
            $user_cookie = PCResponseCookie::lifetimeCookie("user", $user->getIdentifier());

            $response = PCResponse::currentResponse();
            $response->addCookie($presence_cookie);
            $response->addCookie($user_cookie);
            PCModelUser::setCurrentUser($user);
            return TRUE;
        }
        return FALSE;
    }
Beispiel #2
0
 /**
  *
  * @param PCException $ex 
  */
 public static function handleException($ex)
 {
     if ($ex->getCode() == 404) {
         header('HTTP/1.1 404 Not Found');
     }
     $request = PCRequest::currentRequest();
     $type = $request->getRequestType();
     $response = PCResponse::currentResponse();
     $response->setResponseCode($ex->getCode());
     $renderer = NULL;
     if ($type == PCRequest::TYPE_AJAX) {
         $result = array('error' => $ex->getMessage());
         $renderer = new PCRendererJSON($result, 404);
     } else {
         if ($type == PCRequest::TYPE_WEB) {
             $renderer = PCRendererHTML::rendererForView('404', array('title' => "Sorry, page not found :("));
         } else {
             if ($type == PCRequest::TYPE_API) {
                 die('API NOT YET SUPPORTED');
             } else {
                 die("UNKNOWN REQUEST TYPE: {$type}");
             }
         }
     }
     $response->setRenderer($renderer);
     $response->sendResponse();
     if (defined('DEBUG')) {
         error_log($ex->getMessage());
         error_log($ex->getTraceAsString());
     }
 }
 public function redirect(){
     
     $response = PCResponse::currentResponse();
     header("location: $this->location");
     //$response->addHeader("location", $this->location);
     $response->setResponseCode(http_response_code());
     $response->sendHeader();
 }
Beispiel #4
0
 /**
  * 
  * @param PCRequest $request
  */
 public function homeAction($request) {
    
     $result = array();
     $result['title'] = "WebSherpa - Home";
     
     $response = PCResponse::currentResponse();
     $renderer = PCRendererHTML::rendererForView("home", $result);
     $response->setRenderer($renderer);
     
     
     return $response;
 }
 /**
  * 
  * @param PCModelApplication $application
  */
 public function doLogout($application)
 {
     session_destroy();
     $response = PCResponse::currentResponse();
     $response->addCookie(PCResponseCookie::expiredCookie("user"));
     $response->addCookie(PCResponseCookie::expiredCookie("presence_c"));
     PCMapperToken::removeTokenForUser($this->user_id, $application->getAppId());
 }