Cakephp ADmad CakePHP-HybridAuth插件引发了异常

时间:2016-04-09 19:51:03

标签: php cakephp-3.0 hybridauth

我正在使用社交身份验证的ADmad / CakePHP-HybridAuth插件。为此,我按照https://github.com/ADmad/CakePHP-HybridAuth给出的文件。我做的与在doc上做的一样,但我面临一个例外: -

您必须为“HybridAuth.newUser”事件附加一个侦听器,该事件会保存新用户记录并返回用户实体。

请帮我解决这个问题。

示例:

的usermodel:

$this->loadComponent('Auth', [
            'authenticate' => [
                'Form' => [
                    'fields' => [
                        'username' => 'username',
                        'password' => 'password'
                    ]
                ],
                'ADmad/HybridAuth.HybridAuth'
            ],
            'loginAction' => [
                'controller' => 'Users',
                'action' => 'login',
                'plugin' => 'Accounts'
            ],
            'loginRedirect' => [
                'controller' => 'Users',
                'action' => 'login',
                'plugin' => 'Accounts'
            ],

        ]);

在App Controller中:

public function login()
    {
        if( $this->Auth->user()){
            $this->redirect(array('action'=>'index', 'controller'=>'Users', 'plugin'=>'Accounts'));
        }else{

            if ($this->request->is('post') || $this->request->query('provider')) {

                $user = $this->Auth->identify();
                if ($user) {
                    $this->Auth->setUser($user);
                    return $this->redirect($this->Auth->redirectUrl());
                }
                $this->Flash->error(__('Invalid username or password, try again'));
            }
        }
    }

在UsersController中:

uint64_t

错误页面 enter image description here

1 个答案:

答案 0 :(得分:-1)

错误在此行

$User = $this-> new Entity (['email' => $profile-> email]);

你应该很好

$User = $this-> newEntity ([ 'username' => 'valorunico', 'user' => $profile-> email, 'role_id' => 1]);

测试看...