0
このコードの問題点は何ですか? コントローラと識別のみがfalseを返します。 私のデータベースの列はsenha(パスワード)と電子メールです。そして、私はサインインできません。 ハッシュ、パスワード255文字を使用しています。 しかし、それは動作していません!Cakephp 3 - 認証ログイン戻る返信
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;
}
私はこの問題を解決する手助けが必要。 データベースの列が異なるため、デフォルトとして使用するつもりはありません。 もっと先にそれはアヤックスになるだろうが、今のところ私は解決できなかったのでそうである!
このサイトは英語のStackOverflowサイトです。ポルトガル語のサイトを使用するには、https://pt.stackoverflow.com/ –
にアクセスしてください。ポルトガル語と英語の両方を解決できます...ブラジル人とポルトガル語はこのサイトをあまり使用しません。それが私が英語で書いた理由です。問題があれば、Google翻訳のテキストが入力されます。 –
.ctpファイルには何がありますか? –