/**
  * 
  * @param PCRequest $request
  * @param PCModelApplication $application
  * @return bool
  */
 public function doLogin($request, $application)
 {
     $param = $request->getParams();
     $userName = $param['uname'];
     $pwd = $param['pwd'];
     $keys = array('username' => $userName, "account_type" => PCModelUser::$TYPE_DEFAULT);
     $user_array = PCModelManager::fetchModelObjectInstances(PCModelUser::getMapper(), $keys, NULL, TRUE);
     $user = $user_array[0];
     if (isset($user) && strcmp($pwd, $user->getPassword()) == 0) {
         $secret = $application->getAppSecret();
         $appId = $application->getIdentifier();
         $time = time();
         $cookieValue = PCAuth::computeHashForString($userName . $time . $secret);
         $distantFuture = PCResponseCookie::getDistantFuture();
         if (PCMapperToken::setTokenForUserWithIdentifier($user->getIdentifier(), $appId, $cookieValue, $distantFuture)) {
             $_SESSION['user'] = $this->user_id = $user->getIdentifier();
             $presence_cookie = PCResponseCookie::lifetimeCookie("presence_c", $cookieValue);
             //setcookie("presence_c", $cookieValue, $expirationTime,"/");
             $user_cookie = PCResponseCookie::lifetimeCookie("user", $user->getIdentifier());
             //setcookie("user",$user->getIdentifier(), $expirationTime,"/");
             $response = PCResponse::currentResponse();
             $response->addCookie($presence_cookie);
             $response->addCookie($user_cookie);
         } else {
             return FALSE;
         }
         return TRUE;
     }
     return FALSE;
 }
Example #2
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;
    }