我有一些代碼可以防止被刪除和禁止的用戶登錄。要清除頭腦,狀態爲-2意味着用戶被刪除,-1意味着用戶被禁止。下面是在本地工作正常的代碼,但在實際上它很糟糕。狀態爲-1或-2的用戶仍可以登錄。我找不到問題所在。CakePHP 2.x無法阻止已刪除和禁止的用戶登錄
if ($this->Auth->login()) {
//first check if the user's status is -1 or -2.
$status = $this->Auth->user('status');
if ($status == '-1') {
$this->Auth->logout();
$this->Session->setFlash(__('This account has been banned. Please contact with us.'));
$this->redirect('/');
} elseif ($status == '-2') {
$this->Auth->logout();
$this->Session->setFlash(__('This account has been deleted, and is not usable anymore.'));
$this->redirect('/');
}
//something else
}
我不知道的範圍鍵,這是2.2版本中的新功能。謝謝(你的)信息!但現在這不適合我。第二種解決方案在當地運作良好,但不在現場。我做了很多調試,但仍然無法解決問題。 – hswner 2012-08-07 02:39:00
你好。現在它也可以在現場使用。我沒有做任何承諾,除了刪除一個緩存文件,它具有路徑app/tmp/cache/persisten/myapp_cake_core_file_map。這很奇怪! – hswner 2012-08-07 02:47:35
範圍鍵對CakePHP 2並不新鮮。 – Predominant 2012-08-07 02:51:59