繁体   English   中英

Cakephp 2.2.4在使用备用验证后不保存Auth用户信息

[英]Cakephp 2.2.4 does not save Auth User Info after using a alternative authenication

我正在尝试为Facebook用户创建身份验证。 现在我检查我的数据库中是否存在fb用户ID,如果确实存在,则会进行身份验证,如果没有,则数据会挖掘用户的facebook信息并创建用户然后再进行身份验证。 它运作成功,问题是,如果我使用类似$this->Auth->user('id'); 值返回null。 我很好奇我可能做错了什么。 下面是我的代码

public function fb_authenticate($data) {
    $this->Auth->fields = array('username' => 'fbid', 'password' => 'fbpassword');
    $this->loadModel('User');
    $user_record = $this->User->find('first', array(
            'conditions' => array('fbid' => $data['user_id'])
    ));
    if(empty($user_record)) {
        $fbu = $this->Facebook->getUserInfo($data['user_id']);
        $user_record = array(
            'User'=>array(
                'username'=>$fbu->username,
                'fbid'=>$data['user_id'],
                'oauth_token'=>$data['oauth_token'],
                'access_token'=>$data['access_token'],
                'firstname'=>$fbu->first_name,
                'lastname'=>$fbu->last_name,
                'fbpassword'=>$this->Auth->password($data['user_id']),
                'role'=>'user'
        ));     
        $this->User->create();
        $this->User->save($user_record,null);
    }
    if (!$this->Auth->login($user_record)) {
       $this->Session->setFlash(__('Invalid username or password, try again'));
    }
}

它验证并允许用户进入,但它不会在Auth组件会话中存储用户信息。 可能是什么问题呢 ??

如果我调试debug($this->Auth->user())我可以看到数据但是如果我单独debug($this->Auth->user('id'));一个字段debug($this->Auth->user('id')); 它返回null

更改$this->Auth->login($user_record)

to $this->Auth->login($user_record['User'])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM