ich möchte gern in mein Admin-Backend die "Remember Me"-Funktion einbauen.
Das Problem, was ich habe, ist, dass komischerweise kein Cookie geschrieben wird.
app_controller
- Code: Alles auswählen
- var $components = array('Auth', 'Cookie', 'Email', 'RequestHandler');
function beforeFilter() {
// Auth
$this->Auth->loginAction = array(Configure::read('Routing.admin') => true, 'controller' => 'users', 'action' => 'login');
$this->Auth->autoRedirect = false;
$this->Auth->logoutRedirect = array(Configure::read('Routing.admin') => true, 'controller' => 'users', 'action' => 'login');
$this->Auth->authError = 'You are not authorized to access that location.';
$this->Auth->loginError = 'You are not logged in. Please make sure that the username and the password are correct.';
//Cookie
$this->Cookie->name = 'backyard_shed';
$this->Cookie->time = '4 weeks';
$this->Cookie->path = '/admin/';
$this->Cookie->domain = $_SERVER['SERVER_NAME'];
$this->Cookie->key = '1234';
}
user_controller
- Code: Alles auswählen
- function admin_login() {
$this->set('title', 'Please log in');
if ($this->Auth->user()) {
if (!empty($this->data)) {
if ($this->data['User']['remember_me']) {
$cookie = array();
$cookie['username'] = $this->data['User']['username'];
$cookie['password'] = $this->data['User']['password'];
$this->Cookie->write('Auth.User', $cookie, true, '+4 weeks');
}
$this->redirect($this->Auth->redirect());
}
}
if (empty($this->data)) {
$cookie = $this->Cookie->read('Auth.User');
if (!is_null($cookie)) {
if ($this->Auth->login($cookie)) {
$this->Session->del('Message.auth');
$this->redirect($this->Auth->redirect());
}
}
}
}
Lese ich mit $this->Cookie->read('Auth.User'); den Cookie gleich nach dem Schreiben, komme ich an die Daten. Suche ich aber im Firefox nach dem Cookie, ist er nicht da. Auch simples Dummy-Cookie anlegen funktioniert nicht.
Übersehe ich irgendeine Kleinigkeit? Hab ich irgendwas vergessen?

