Bonsoir,
Voici comment moi j'ai fait :
UsersController.php :
public function login(){
if ($this->request->is('post')) {
if ($this->Auth->login()) {
if ($this->request->data'User']'rememberMe'] == 1) {
unset($this->request->data'User']'rememberMe']);
$this->request->data'User']'password'] = $this->Auth->password($this->request->data'User']'password']);
$this->Cookie->write('rememberMeCookie', $this->request->data'User'], true, '2 weeks');
}
$this->Session->setFlash("Vous êtes maintenant connecté","alert", array(
'plugin' => 'BoostCake',
'class' => 'alert-success autoclose'
));
$this->redirect('/');
}else{
$this->Session->setFlash("Identifiants incorrects","alert", array(
'plugin' => 'BoostCake',
'class' => 'alert-danger autoclose'
));
}
}
}
AppController.php :
public function beforeFilter() {
parent::beforeFilter();
if (!$this->Auth->loggedIn() && $this->Cookie->read('rememberMeCookie')) {
$cookie = $this->Cookie->read('rememberMeCookie');
$user = $this->User->find('first', array(
'conditions' => array(
'User.mail' => $cookie'mail'],
'User.password' => $cookie'password']
)
));
if ($user && !$this->Auth->login($user'User'])) {
$this->redirect('/users/logout'); // destroy session & cookie
}
}
}
Cordialement :)