authentication - Cakephp 3 - Auth Login Return False -
what's problem code? controller , identify return false! database column senha (password) , email. , can not sign in. using hash, password 255 characters , right. it's not working!
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 required') ->notempty('senha', 'a password 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; }
i need solving problem. columns in database different, not intend use default. more ahead become ajax because not solve!
change 'fields' => ['email' => 'email', 'senha' => 'senha']
'fields' => ['username' => 'email', 'password' => 'senha']
with config, don't need custom finder, unless require select columns. using default finder, unset properties.
make sure login form controls , table columns named email
, senha
then, i'm wondering if eighter way should load authcomponent in appcontroller.
Comments
Post a Comment