我正在尝试建立一个简单的登录系统,但我遇到了一个我无法解决的特殊问题。我有以下页面执行自解释操作。它们被标记为便于访问。
cake/ (home page; must be logged in)
cake/login (must be logged in)
cake/logout (must be logged in)
cake/add (must be logged in)
除非我执行以下一系列操作,否则一切似乎都有效:
1. log in
2. go to cake/logout to log out (login works immediately after this step)
3. go to cake/logout again immediately
4. attempt to log in but cake/login is just re-displayed and I'm not logged in
5. attempt to log in again and it is successful
我注意到$this->Session->flash('auth')
在步骤3之后为假,但在4之后它不是假的。我尝试在注销之前或之后销毁会话而没有效果。有什么想法吗?
我的代码位如下:
class UsersController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add');
}
public function add() {
if (!empty($this->data)) {
$this->User->create();
if ($this->User->save($this->data)) {
$this->Session->setFlash('User created!');
$this->redirect(array('action'=>'login'));
} else {
$this->Session->setFlash('Please correct the errors');
}
}
}
public function login() {
}
public function logout() {
$this->Session->destroy(); // makes no difference
$this->redirect($this->Auth->logout()); // redirected to login() by default
}
}
class AppController extends Controller {
public $components = array('Auth', 'Session');
}
答案 0 :(得分:0)
我认为您在登录后被重定向到退出屏幕。 当您转到您无法访问的页面(如注销屏幕)时,您将被重定向到登录状态。 输入名称和密码后,您将恢复原始请求。 当原始请求恰好是注销页面时,就会发生注销并将您发送回登录。