示例#1
0
 public static function getInstance($arg)
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self($arg);
     }
     return self::$instance;
 }
示例#2
0
文件: FB.php 项目: anqqa/Anqh
 /**
  * Initializes Facebook Connect
  */
 public static function init()
 {
     widget::add('foot', html::script(array('js/fbconnect.js', 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US')));
     widget::add('foot', html::script_source("FB.init('" . FB::$config['api_key'] . "');"));
     // Add logged in Facebook user id to session for easier access
     if ($logged_in = FB::instance()->get_loggedin_user()) {
         $_SESSION['fb_uid'] = $logged_in;
     }
 }
示例#3
0
文件: member.php 项目: anqqa/Anqh
 /**
  * Facebook connect
  */
 public function _facebook()
 {
     $this->tab_id = 'facebook';
     // Only owner may view this for now
     $owner = $this->user && $this->member->id == $this->user->id;
     if (!$owner) {
         url::redirect(url::user($this->member));
     }
     // Are we logged in Facebook?
     $fb_uid = FB::instance()->get_loggedin_user();
     $external_user = $fb_uid ? $this->member->find_external_by_id($fb_uid) : $this->member->find_external_by_provider(User_External_Model::PROVIDER_FACEBOOK);
     // Did we do an action?
     if (request::method() == 'post') {
         // Connect accounts
         if ($_POST['connect'] == User_External_Model::PROVIDER_FACEBOOK && $fb_uid) {
             if (!$external_user->loaded() && $this->member->map_external($fb_uid, User_External_Model::PROVIDER_FACEBOOK)) {
                 // Map succesful
             } else {
                 // Map failed
             }
         } else {
             // Not connected or invalid post
         }
         url::redirect(url::user($this->member) . '/facebook');
     }
     $parameters = array();
     if ($fb_uid) {
         $parameters['fb_uid'] = $fb_uid;
     }
     if ($external_user->loaded) {
         $parameters['external_user'] = $external_user;
     }
     widget::add('main', View::factory('member/facebook', $parameters));
     $this->_side_views();
 }
示例#4
0
文件: visitor.php 项目: anqh/core
 /**
  * Attempt to login with 3rd party account
  *
  * @return  bool
  */
 public function external_login($provider)
 {
     if ($provider == Model_User_External::PROVIDER_FACEBOOK && ($fb_uid = FB::instance()->get_loggedin_user())) {
         // Load the external user
         $user = Model_User::find_user_by_external($fb_uid, $provider);
         if ($user->loaded() && $this->complete_login($user)) {
             $this->_session->set($this->_config['session_key'] . '_provider', $provider);
             return true;
         }
     }
     return false;
 }
示例#5
0
文件: Visitor.php 项目: anqqa/Anqh
 /**
  * Log out a user by removing the related session variables.
  *
  * @param   boolean  $destroy  completely destroy the session
  * @return  boolean
  */
 public function logout($destroy = false)
 {
     // Delete the autologin cookie to prevent re-login
     if (cookie::get($this->config['cookie_name'])) {
         cookie::delete($this->config['cookie_name']);
     }
     // Logout 3rd party?
     if (FB::enabled() && Visitor::instance()->get_provider()) {
         $this->session->delete($this->config['session_key'] . '_provider');
         try {
             FB::instance()->expire_session();
         } catch (Exception $e) {
         }
     }
     // Destroy the session completely?
     if ($destroy === true) {
         $this->session->destroy();
     } else {
         // Remove the user from the session
         $this->session->delete($this->config['session_key']);
         // Regenerate session_id
         $this->session->regenerate();
     }
     // Double check
     return !$this->logged_in();
 }