I am new to cakephp and started learning cakephp3.2 directly I have created a function in my custom controller as follows.
public function login(){
if($this->request->is('post')){
$user = $this->auth->identify();
if($user){
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}else{
$this->Flash->error(__('Username or password is incorrect'), [
'key' => 'auth'
]);
}
}
}
class AppController extends Controller
{
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth',[
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
]
],
'authError' => 'Did you really think you are allowed to see that?',
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
],
'storage'=>'Session'
]);
$this->Auth->allow(['display']);
}
public function beforeRender(Event $event)
{
if (!array_key_exists('_serialize', $this->viewVars) &&
in_array($this->response->type(), ['application/json', 'application/xml'])
) {
$this->set('_serialize', true);
}
}
}
I don't understand how to deal with it.Should I load any external component or helper ?