Exemplo n.º 1
0
<?php

require_once "lib/ProxyAPIClient.php";
$fb_logged_in = FacebookExt::Instance();
//singleton
$this->code = $this->getRequestParameter('code');
$short_lived_access_token = $this->getRequestParameter('access_token');
$fb_logged_in::$arguments['short_lived_access_token'] = $short_lived_access_token;
//this function is called through a proxy design pattern
//Facebook server side flow
if ($this->code) {
    $fb_logged_in::$arguments['code'] = $this->code;
}
$this->user = $fb_logged_in->GetFBLoginStatus();
$this->photo = $fb_logged_in->MyFBPhoto();
Exemplo n.º 2
0
 public function get_fb_login_status()
 {
     if (isset(parent::$arguments['short_lived_access_token'])) {
         $access_token = parent::$arguments['short_lived_access_token'];
     }
     if (isset(parent::$arguments['long_lived_access_token'])) {
         $access_token = parent::$arguments['long_lived_access_token'];
     }
     if (!isset($access_token)) {
         return FALSE;
     }
     $config = array();
     $config['appId'] = sfConfig::get('app_facebook_app_id');
     $config['secret'] = sfConfig::get('app_facebook_app_secret');
     $config['fileUpload'] = false;
     // optional
     $facebook = new Facebook($config);
     $facebook->setAccessToken($access_token);
     $access_token = $facebook->getAccessToken();
     //fb_long_lived_token(); //check which multiton key
     $user_id = $facebook->getUser();
     self::$fb_uid = $user_id;
     if ($user_id) {
         // We have a user ID, so probably a logged in user.
         // If not, we'll get an exception, which we handle below.
         try {
             $user_profile = $facebook->api('/me', 'GET');
             $this->email_from_facebook = $user_profile['email'];
             $this->user = Doctrine_Core::getTable('SfGuardUser')->findOneByEmailAddress($this->email_from_facebook);
             //die($this->user);
             //if sfguard doesn't have this user, create it
             if ($this->user == '') {
                 //$this->sync_accounts_maint();
                 $this->create_sf_user($user_profile);
                 $this->user = Doctrine_Core::getTable('SfGuardUser')->findOneByEmailAddress($this->email_from_facebook);
             }
             //return the user so the action can log in the user
             return $this->user;
         } catch (FacebookApiException $e) {
             return $e;
         }
     } else {
         // No user, print a link for the user to login
         //return $facebook->getLoginUrl() . "&redirect_uri=http://".sfConfig::get('app_host_name')."/frontend_dev.php/account/login";
         return FALSE;
     }
     return FALSE;
 }
 static function allInstances()
 {
     return FacebookExt::allInstances();
 }
Exemplo n.º 4
0
 public function get_fb_login_status()
 {
     //get access token, exchange code for token
     parent::$arguments['access_token'] = $this->get_fb_access_token();
     //two types of access tokens, short lived and long lived
     //client side flow uses a short lived access token
     if (isset(parent::$arguments['access_token'])) {
         $access_token = parent::$arguments['access_token'];
     } else {
         return FALSE;
     }
     //Facebook SDK config
     $config = array();
     $config['appId'] = $this->fb_app_id;
     $config['secret'] = sfConfig::get('app_facebook_app_secret');
     $config['fileUpload'] = false;
     // optional
     $facebook = new Facebook($config);
     $facebook->setAccessToken($access_token);
     $access_token = $facebook->getAccessToken();
     //fb_long_lived_token(); //check which multiton key
     $user_id = $facebook->getUser();
     self::$fb_uid = $user_id;
     if ($user_id) {
         // We have a user ID, so probably a logged in user.
         // If not, we'll get an exception, which we handle below.
         try {
             $user_profile = $facebook->api('/me', 'GET');
             $this->email_from_facebook = $user_profile['email'];
             $this->user = Doctrine_Core::getTable('SfGuardUser')->findOneByEmailAddress($this->email_from_facebook);
             //if sfguard doesn't have this user, create it
             if ($this->user == '') {
                 //$this->sync_accounts_maint();
                 $this->CreateUser($user_profile);
                 $this->user = Doctrine_Core::getTable('SfGuardUser')->findOneByEmailAddress($this->email_from_facebook);
             }
             //return the user
             return $this->user;
         } catch (FacebookApiException $e) {
             return $e;
         }
     } else {
         return FALSE;
     }
     return FALSE;
     //default
 }