1
我正在使用cakePHP 2.2。CakePHP Auth-> loginRedirect不工作
在我的我的應用程序控制器的前過濾器,我有以下:
// 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");
}
第一和第二,如果公司正常工作和用戶重定向到登錄相應頁面,但是第三重定向不起作用在所有情況下,它只是讓你登錄頁面,但它確實顯示登錄函數的flash_success消息?
任何人都可以指向正確的方向嗎?
在此先感謝
*蒂姆requrested添加信息*
過濾器和登錄功能之前,用戶控制器:
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');
}
}
只是一個延伸,但你沒有在頁面控制器上拒絕用戶的'isAuthorized()'覆蓋?重定向如何被調用?你可以在登錄函數中丟失諸如'$ this-> redirect($ this-> Auth-> redirect())'的調用嗎? – Grambot
默認情況下不是''admin'=> false'?你需要那些額外的參數嗎? –
讓我們在用戶控制器中看到您的登錄功能和beforeFilter –