0
这段代码有什么问题? 控制器和标识只返回false! 我的数据库列是senha(密码)和电子邮件。我无法登录。 我使用散列,密码为255个字符,并且都是正确的。 但它不工作!Cakephp 3 - Auth登录返回False
ContaController.php
public function initialize() {
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => ['email' => 'email', 'senha' => 'senha'],
'userModel' => 'Conta',
'finder' => 'auth',
]
],
'authorize' => ['Controller'],
'loginAction' => [
'controller' => 'Conta',
'action' => 'index',
],
'loginRedirect' => [
'controller' => 'Conta',
'action' => 'minha-agenda'
],
'logoutRedirect' => [
'controller' => 'Conta',
'action' => 'index',
],
'storage' => 'Memory'
]);
$this->Auth->allow(['index']);
}
public function index() {
if ($this->request->is('ajax') || $this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
// return $this->redirect($this->Auth->redirectUrl());
echo 'success';
} else {
var_dump($user);
echo 'incorrect';
}
}
}
ContaTable.php
public function initialize(array $config) {
parent::initialize($config);
$this->setTable('alunos');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsToMany('Alunos', [
'foreignKey' => 'interesses_id',
'targetForeignKey' => 'alunos_id',
'joinTable' => 'alunos_interesses'
]);
}
public function validationDefault(Validator $validator) {
$validator
->notEmpty('email', 'A username is required')
->notEmpty('senha', 'A password is required');
return $validator;
}
public function findAuth(\Cake\ORM\Query $query, array $options) {
$query
->select(['id', 'email', 'senha'])
->where(['Conta.email' => $options['email']])
->andWhere(['Conta.senha' => $options['senha']]);
return $query;
}
我需要帮助解决这个问题。 数据库中的列是不同的,所以我不打算将它用作默认值。 更进一步,它将成为ajax,但现在它是如此,因为我解决不了!
此网站是StackOverflow英文网站。要使用葡萄牙语网站,请访问https://pt.stackoverflow.com/ –
葡萄牙语和英语都可以解决......巴西人和葡萄牙人不会非常使用这个网站!这就是我用英文写作的原因。任何问题都会在Google翻译中输入文字! –
你的.ctp文件是什么? –