Example #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;
    }
 /**
  *  * Posta sulla timeline di Facebook (se possibile)
  * @param array $reviewDescription
  * @param PCModelWebsite $onSite
  * @param PCModelUserOauth $user
  * @return boolean
  */
  public static function postReviewToFacebook($reviewDescription, $onSite, $user){
     PCAutoloader::importLibrary('facebook');
     
     $oauth = $user->getOauthStore();
     if($oauth == null){
        
         return FALSE;
     }
    
     $domain = $onSite->getDomain();
     $usa = $reviewDescription['usability'];
     $rel = $reviewDescription['reliability'];
     $cont = $reviewDescription['contents'];
     $vote = sprintf("%.1f",(($usa+$rel+$cont)/3.0));
     $text = "I've just reviewed $domain (Vote: $vote) using http://websherpa.me : ".$reviewDescription['comment'];
     
     $facebook = new Facebook(array(
         "appId" => FB_APP_ID,
         "secret" => FB_APP_SECRET,
         "cookie" => true
     ));
     
     $facebook->setAccessToken($oauth['oauth_token']);
     
     try {
         $result = $facebook->api("/me/feed", 'post', array(
             'message' => $text,
             'name' => 'WebSherpa',
             'link' =>  "http://websherpa.me/sites/site?id=".$onSite->getIdentifier(),
             'picture' => 'http://websherpa.me/public/fresh/img/logo_footer.png',
         ));
        
         return isset($result['id']);
         
     } catch (FacebookApiException $exc) {
         c_dump($exc);
         return FALSE;
     }
     return FALSE;
 }
Example #3
0
    /**
     * 
     * @param string $user_identifier
     * @param int $service il codice servizio (es Facebook o Twitter)
     * @return array
     */
    public static function getOauthConfig($user_identifier, $service ){
        $val = array(
            "user_identifier" => $user_identifier,
            "oauth_provider" => $service
        );

        $inst = PCModelManager::fetchModelObjectInstances(PCModelUserOauth::getMapper(), $val);
        if(count($inst) == 0 ) return NULL;
        return $inst[0];
    }
 /**
  * Posta sulla timeline di twitter
  * @param array $reviewDescription
  * @param PCModelWebsite $onSite
  * @param PCModelUserOauth $user
  * @return boolean
  */
 public static function postReviewToTwitter($reviewDescription, $onSite ,$user){
     PCAutoloader::importLibrary('twitter');
     
     $oauth = $user->getOauthStore();
     if($oauth == null) return FALSE;
     
     $connection = new TwitterOAuth(TW_CONSUMER_KEY, TW_CONSUMER_SECRET, $oauth['oauth_token'], $oauth['oauth_secret']);
     $domain = $onSite->getDomain();
     $usa = $reviewDescription['usability'];
     $rel = $reviewDescription['reliability'];
      $cont = $reviewDescription['contents'];
      $vote = sprintf("$.1f",(($usa+$rel+$cont)/3.0));;
     $text = "I've just reviewed http://$domain (Vote: $vote) using @WebSherpa_me http://websherpa.me/sites/site?id=".$onSite->getIdentifier();
     
     $status = $connection->post('statuses/update', array('status' => $text));
     if(isset($status->errors)) return FALSE;
     return TRUE;
 }