I have one table whose name is admins. Its contains username and password fields. My sales user use admins table for the sales login. I want to login sales using AuthComponent. I have write code for this as below.
AppController
public $components = [
'Auth' => [
'loginAction' => [
'controller' => '',
'action' => 'login'
],
'logoutRedirect' => [
'controller' => '',
'action' => 'login'
],
'loginRedirect' => [
'controller' => '',
'action' => 'deshboard'
],
'className' => 'MyAuth'
]]
public function beforeFilter() {
$this->Auth->authenticate = [
'Form' => ['userModel' => 'admin', "fields" => ["username" => "username",
"password" => "password"]
]];
}
SalesController
function login() {
$post = $this->request->data('Admin');
if ($this->request->is('post') && !empty($post)) {
//var_dump($this->Auth->login());exit;
if ($this->Auth->login()) {
return $this->Auth->redirect($this->Auth->redirectUrl());
}
// perform login throttling (failure and block) if Sales or Admin portal
// set an appropriate failure message
}
}
When I have print the return value of auth->login() function. Its always return false.
I have search a lots for this issue but I am unable to find any proper answer.
Thanks in advance for helping me.