I'm developing my website in cakephp 3.x. In that I want remember me functionality for login the user.
I have done lots of seraching(R&D) on google but I can't found anything helpful for me. I have tried to apply CakePHP remember me with Auth
But it doesnot helped me.
I have username as email & password as password field in my database.
If anyone has any idea then please share it with me.
My login function :
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
if ($this->request->data['rememberMe'] == "on") {
$cookie = array();
$cookie['username'] = $this->request->data['email'];
$cookie['password'] = $this->request->data['password'];
$this->Cookie->write('rememberMe', $cookie, true, "1 week");
unset($this->request->data['rememberMe']);
}
if (empty($this->data)) {
$cookie = $this->Cookie->read('rememberMe');
if (!is_null($cookie)) {
$user = $this->Auth->identify();
if ($user) {
$this->redirect($this->Auth->redirectUrl());
} else {
$this->Cookie->destroy('rememberMe'); # delete invalid cookie
$this->Session->setFlash('Invalid cookie');
$this->redirect('login');
}
}
}
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->set('Invalid username or password, try again', ['element' => 'error']);
}