Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP验证Facebook连接不工作(无插件)_Php_Facebook_Facebook Graph Api_Cakephp - Fatal编程技术网

CakePHP验证Facebook连接不工作(无插件)

CakePHP验证Facebook连接不工作(无插件),php,facebook,facebook-graph-api,cakephp,Php,Facebook,Facebook Graph Api,Cakephp,我有一个奇怪的情况,我不知道如何调试它。 一个客户请求为CakePHP版本1.2.12上的网站进行facebook登录。 所以我使用了FacebookPHPSDK并遵循标准程序。如果用户未注册,则使用来自Facebook的数据注册并生成密码等。 然后,如果该用户已注册,并与他的facebook帐户连接,我想使用CakePHP Auth组件让他登录。 问题是,它将我踢出,因为我无法进行身份验证。 以下是我所做的: public function facebook_login_register()

我有一个奇怪的情况,我不知道如何调试它。 一个客户请求为CakePHP版本1.2.12上的网站进行facebook登录。 所以我使用了FacebookPHPSDK并遵循标准程序。如果用户未注册,则使用来自Facebook的数据注册并生成密码等。 然后,如果该用户已注册,并与他的facebook帐户连接,我想使用CakePHP Auth组件让他登录。 问题是,它将我踢出,因为我无法进行身份验证。 以下是我所做的:

public function facebook_login_register() {
    $fbUser = $this->Facebook->getUser();
    if ($fbUser) {
        //gets FB details about my profile
        $fbUser = $this->Facebook->api('/me');
        $registeredUser = $this->UserProfile->find('first', array('conditions' => array('UserProfile.email' => $fbUser['email']),
            'fields' => array('UserProfile.email')));
        if (!$registeredUser) {
        ... registration ...
        }
        else{
            $usernameDisplay = $this->User->find('first', array('conditions' => array('User.username' => $fbUser['username']),
                                                                'fields' => array('User.username_display')));
            }

            $fb['username'] = $fbUser['username'];
            $fb['password'] = $usernameDisplay['User']['username_display'];

            $this->Auth->fields = array(
                'username' => 'username',
                'password' => 'username_display_encoded' //the encoded display_name (encoded with $this->Auth->password() or Security::hash(...). The result is correct when testing it for hashing)
            );

            if ($this->Auth->login($fb)) {
               echo 'ok';
            }
            else{
               echo 'not ok';
            }
。。。。 }

所以当我这样做的时候,它只是把我踢出了else分支

提前感谢您的帮助!
干杯。

我认为您的登录失败,因为您有一个映射到密码的错误字段-用户名\u显示\u编码字段甚至不存在于您为登录传递的数组
$fb
。您要传递到
$this->Auth->login()
的数组需要匹配用户模型的用户名和密码字段,因为它将根据数据库检查您传递的内容

$user = $this->User->find('first', array('conditions' => array('User.username' => $fbUser['username'])));

$this->Auth->fields = array(
    'username' => 'username',
    'password' => 'username_display' 
);

if ($this->Auth->login($user['User'])) {
     echo 'ok';
}
else{
     echo 'not ok';
}
另外,看看哪一个看起来可能有用,尽管它是用于更新版本的蛋糕