2012-04-17 38 views
3

我使用webtechnick的CakePHP-Facebook-Plugin(https://github.com/webtechnick/CakePHP-Facebook-Plugin/),並且我正在識別用戶是否已經登錄Facebook的一些麻煩。問題是:我登錄Facebook,然後打開我的網站(localhost.localdomain),我沒有登錄。然後我刷新我的網頁,我登錄。 以上是我使用的代碼。我已經測試過了,在第一次請求中,$ this-> Connect-> user()調用返回false(第一個和第二個),然後頁面呈現,我認爲一些魔術是由init或者FacebookHelper->登錄方法,因爲如果我沒有重定向的話,它說我在線並使用我的網站;與重定向設置,它顯示標籤和我登錄的第二個請求。Webtechnick CakePHP-Facebook-Plugin必須要求兩次認證登錄的用戶

我試着初始化FacebookHelper並在beforeFilter上調用「login」,但沒有成功(有和沒有重定向)。

此外,顯示Facebook的登錄或註銷按鈕的邏輯在beforeFilter中進一步完成,根據$ this-> Session-> check('Auth.User.id')的值定義特定的佈局。

27  public function beforeFilter() { 
28 
29   try { 
30    $user = $this->Auth->user(); 
31    $fb_user = $this->Connect->user(); 
32   } catch (FacebookApiException $e) { 
33   } 
34   Configure::write('VertWeb.show_tabs', true); 
35   if ($fb_user = $this->Connect->user()) { 
36    if (!$this->Auth->loggedIn()) { 
37     if (!isset($fb_user['error_code'])) { 
38      $this->loadModel('User'); 
39      $this->User->recursive = -1; 
40      if (($user = $this->User->findByFacebookId($fb_user['id'])) || 
41       ($user = $this->User->findByEmail($fb_user['email']))) { 
42       
43       $this->Auth->login($user); 
44       $this->Session->write('Auth.FacebookUser', $fb_user); 
45       $this->Session->write('Auth.User', $user['User']); 
46       $this->Session->write('Auth.FacebookUserPicture', FB::api('/me?fields=picture')); 

親切的問候, 丹尼爾

回答

2

我有這個問題,我解決它puting在初始化該線(和刪除啓動方法)

if (!$this->noAuth && !empty($this->uid)) { 
    $this->__syncFacebookUser(); 
} 
相關問題