【问题标题】:webtechnick Facebook logout not workingwebtechnick Facebook注销不起作用
【发布时间】:2011-12-20 12:31:46
【问题描述】:

我正在使用 webtechnick facebook 插件,我已经设置好了所有内容,并且它的 FB 登录效果很好。

我正在使用$fbc =$this->Connect->User(); 获取登录用户的 FB 详细信息

并使用

<?php 
    echo $facebook->login(array('perms' => 'email,publish_stream','size'=>'small')); 
?>

<?php
    echo $this->Facebook->logout(); 
?>

分别用于登录、注销。登录后我正在获取用户的详细信息,但在执行 logout() 后不会取消设置;

我正在使用 webtechnick fb 插件版本 3.1.1 。请帮帮我

【问题讨论】:

    标签: cakephp facebook


    【解决方案1】:

    我的帮助没有多大帮助,因为我还没有真正找到解决方案。好消息是你并不孤单:

    https://github.com/webtechnick/CakePHP-Facebook-Plugin/issues/43

    我可以告诉你的是,facebook cookie (fbsr_{facebook_app_id}) 要么没有删除,要么正在重新创建,这就是问题的根源。

    编辑

    我可能已经发现这里发生了什么。直到那天晚上,我才费心设置我的 .htaccess 文件,而且 http:/www.example.com 和 http:/example.com 都是有效的。

    在我的 facebook 应用程序中,我将 example.com 设置为域并将站点 URL 指向 www.example.com。

    使用 fbsr_{app id} cookie,我注意到它有时在 http://example.com 上,而我的 cakephp cookie 在 www 上。

    我尝试在我的 facebook 应用程序中更改 URL(添加 www,删除 www),然后还开始在 .htaccess 中执行重写规则以添加或删除 www。我刚刚从我的 facebook 应用程序中完全删除了 appdomain,强制 www。到域,现在一切都是洁净的。

    所以我认为诀窍是

    1. facebook 应用中没有应用域
    2. 通过 .htaccess 修复 www 的规范化

    这可以确保 cakephp 和 facebook cookie 都保存到相同的域中,并且当您注销时,它们会从所述域中删除。

    希望这是有道理的......

    【讨论】:

      【解决方案2】:

      我知道现在对这篇文章提出一些建议为时已晚。仍然觉得它可能会对后来阅读这篇文章的人有所帮助。

      我也面临插件的注销问题,如果操作是“注销”,我已经修改了插件中 ConnectComponent 中的一个函数以清除其会话详细信息。下面是修改后的函数:

      private function __syncFacebookUser(){
      
              if($this->Controller->params['action'] == 'logout')
                  {
                      $this->Controller->Session->delete('FB');
                      $this->uid = null;
                      $this->Controller->Session->delete('Auth.User');
                  }
                  else
                  {
                  if(!isset($this->Controller->Auth)){
                  return false;
              }
      
              $Auth = $this->Controller->Auth;
              if (!$this->__initUserModel()) {
                  return false;
              }
              // if you don't have a facebook_id field in your user table, throw an error
              if(!$this->User->hasField('facebook_id')){
                  $this->__error("Facebook.Connect handleFacebookUser Error.  facebook_id not found in {$Auth->userModel} table.");
                  return false;
              }
      
              // check if the user already has an account
              // User is logged in but doesn't have a 
              if($Auth->user('id')){
                  $this->hasAccount = true;
                  $this->User->id = $Auth->user($this->User->primaryKey);
                  if (!$this->User->field('facebook_id')) {
                      $this->User->saveField('facebook_id', $this->uid);
                  }
                  return true;
              } 
              else {
                  // attempt to find the user by their facebook id
                  $this->authUser = $this->User->findByFacebookId($this->uid);
                  //if we have a user, set hasAccount
                  if(!empty($this->authUser)){
                      $this->hasAccount = true;
                  }
                  //create the user if we don't have one
                  elseif(empty($this->authUser) && $this->createUser) {
                      $this->authUser[$this->User->alias]['facebook_id'] = $this->uid;
                      $this->authUser[$this->User->alias][$this->modelFields['password']] = $Auth->password(FacebookInfo::randPass());
                      if($this->__runCallback('beforeFacebookSave')){
                          $this->hasAccount = ($this->User->save($this->authUser, array('validate' => false)));
                      }
                      else {
                          $this->authUser = null;
                      }
                  }
                  //Login user if we have one
                  if($this->authUser){
                      $this->__runCallback('beforeFacebookLogin', $this->authUser);
                      $Auth->authenticate = array(
                          'Form' => array(
                              'fields' => array('username' => 'facebook_id', 'password' => $this->modelFields['password'])
                          )
                      );
                      if($Auth->login($this->authUser[$this->model])){
                          $this->__runCallback('afterFacebookLogin');
                      }
                  }
                  return true;
              }
          }
      }
      

      现在对我来说,facebook 插件在 facebook connect 上运行良好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-28
        • 1970-01-01
        • 2015-11-08
        • 2014-04-04
        • 2016-10-28
        • 2016-12-20
        • 2013-03-24
        • 1970-01-01
        相关资源
        最近更新 更多