Example #1
0
 /**
  * @method GET
  * @api connect
  */
 public function connect()
 {
     $userID = User::getID();
     $appID = Social::getSettings('appID');
     $appSecret = Social::getSettings('appSecret');
     $facebook = new Facebook(array('appId' => $appID, 'secret' => $appSecret));
     // Get User ID
     $user = $facebook->getUser();
     if ($user) {
         try {
             $user_profile = $facebook->api('/me');
         } catch (FacebookApiException $e) {
             $user = null;
         }
         $db = DB::instance();
         $data = $db->select('facebook', array('facebookID' => $user_profile['id']));
         //
         if (count($data) == 0) {
             $db->insert('facebook', array('userID' => $userID, 'facebookID' => $user_profile['id']));
         }
         die('<script>window.close()</script>');
     } else {
         $params = array('redirect_uri' => 'http://localhost/openfantasy/web/facebook/connect', 'scope' => 'email');
         die('<script>top.location.href="' . $facebook->getLoginUrl($params) . '";</script>');
     }
 }