Example #1
0
 private function getSession()
 {
     //only try to find a session once even if we failed.
     if ($this->fb_session_tried) {
         return $this->fb_session;
     }
     if (!$this->fb_session) {
         $userinfo = vB::getCurrentSession()->fetch_userinfo();
         if ($userinfo['fbaccesstoken']) {
             $this->setSession($userinfo['fbaccesstoken']);
         }
     }
     if (!$this->fb_session) {
         $authtoken = $this->getAuthFromPHPSession();
         if ($authtoken) {
             $this->setSession($authtoken);
         }
     }
     if (!$this->fb_session) {
         //The javascript helper uses cookies internally.  We don't really want to be dealing
         //with cookies here, however unwinding this make require getting deeper into the
         //Facebook SDK than is prudent.
         $helper = new Facebook\FacebookJavaScriptLoginHelper();
         try {
             $this->fb_session = $helper->getSession();
             if ($this->fb_session) {
                 $this->fb_session->validate();
                 $this->storeInPHPSession($this->fb_session->getToken());
             }
         } catch (Facebook\FacebookAuthorizationException $e) {
             //deliberate fallthrough.  If we don't authorize we'll treat the
             //user as not logged in but we will assume that FB is enabled.
             //usually this means we have an expired token and the user will
             //need to log in again.
             $this->fb_session = null;
         }
     }
     $this->fb_session_tried = true;
     return $this->fb_session;
 }
Example #2
0
 /**
  * Autologin
  *
  * @param $arrCookieData The Data ot the Session-Cookies
  * @return bool
  */
 public function autologin($arrCookieData)
 {
     $this->init_fb();
     try {
         $helper = new Facebook\FacebookJavaScriptLoginHelper();
         $session = $helper->getSession();
         if ($session) {
             $me = $this->getMe($session);
             if ($me) {
                 $uid = $me['uid'];
                 $userid = $this->pdh->get('user', 'userid_for_authaccount', array($uid, 'facebook'));
                 if ($userid) {
                     $userdata = $this->pdh->get('user', 'data', array($userid));
                     return $userdata ? $userdata : false;
                 }
             }
         }
     } catch (Exception $e) {
         $this->core->message($e->getMessage(), "Facebook Exception autologin()", 'red');
     }
     return false;
 }