我正在使用 cakePHP 2.2。
在我的应用控制器之前的过滤器中,我有以下内容:
// Admin
if($this->Auth->user('group_id') == '12') {
$this->Auth->allow('admin_index');
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'admin' => false);
$this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'index', 'admin' => TRUE);
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login', 'admin' => false);
$this->set("group", "admin");
// Staff
} elseif($this->Auth->user('group_id') == '13') {
$this->Auth->allow('admin_index');
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'admin' => false);
$this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'index', 'admin' => TRUE);
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login', 'admin' => false);
$this->set("group", "staff");
// Users
} else {
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'admin' => false);
$this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'index', 'admin' => false);
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login', 'admin' => false);
$this->set("group", "user");
}
第一个和第二个 if 工作正常并将用户重定向到登录时的相应页面,但是第三个重定向根本不起作用,它只是让您留在登录页面上,但它确实显示来自登录功能的 flash_success 消息? ??
谁能指出我正确的方向?
提前致谢
*添加了蒂姆要求的信息*
过滤和登录功能之前的用户控制器:
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('logout');
$this->Auth->allow('login');
$this->Auth->allow('forgetpwd');
$this->Auth->allow('reset');
$this->Auth->allow('initDB');
$this->Auth->allow('register');
//$this->Auth->allow('admin_importOldUsers');
//$this->Auth->allow('*');
}
public function login() {
if ($this->request->is('post')) {
$userStatusCheck = $this->User->find('first',array('conditions'=>array('User.username'=>$this->request->data['User']['username'])));
// If user is not deleted
if ($userStatusCheck['User']['live'] == 1) {
// Users status.
/* 1 = Disabled, 2 = Enabled, 3 = Waiting for Auth, 4 = refer to Darren */
$us = $userStatusCheck['User']['user_status_id'];
// If account is disabled
if ($us == 1) {
$this->Session->setFlash('Your account has been disabled, please conntact our support team.', 'flash_failure');
}
// If account is waiting for authorisation
else if ($us == 3) {
$this->Session->setFlash('Your account is waiting to be authorised', 'flash_failure');
}
// If accoutn is referred to Darren
else if ($us == 4) {
$this->Session->setFlash('Your account is waiting to be authorised', 'flash_failure');
}
// Account is enabled, proceed to login
else if ($us == 2) {
if ($this->Auth->login()) {
if ($this->Session->read('Auth.User')) {
$this->Session->setFlash('You are logged in!', 'flash_success');
//$this->redirect($this->Auth->redirect());
if($this->Auth->user('group_id') == '12' OR $this->Auth->user('group_id') == '13'){
$this->redirect('/admin/');
} else {
$this->redirect($this->Auth->redirect());
}
}
}
else {
$this->Session->setFlash('Your username or password was incorrect.', 'flash_failure');
}
}
} else {
$this->Session->setFlash('Your account has been disabled, please conntact our support team.', 'flash_failure');
}
}