I’m trying to write cookie after logging in but it doesn’t seem to save anything.
Am I doing something wrong?
function login() {
if ($this->Session->read('Auth.User')) {
if($this->data['User']['remember']){
$cookie = array();
$cookie['username'] = $this->data['User']['email'];
$cookie['password'] = $this->data['User']['password'];
$this->Cookie->write('Auth.User', $cookie, true, '+2 weeks');
unset($this->data['User']['remember']);
}
$this->Session->setFlash('You are logged in!');
$this->redirect(array('action' => 'logs'));
} else {
$this->Session->setFlash('Invalid username and password combination');
$this->redirect('/', null, false);
}
}
For executing your login function, you need to set $this->Auth->autoRedirect = false in to a beforeFilter statement (in AppController or UsersController)
This is a complete login function also logout function: