CakePHP 2.2 を使用しています。
私のApp Controllerの前のフィルターには、次のものがあります。
// 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");
}
1 番目と 2 番目の if は正常に機能し、ログイン時にユーザーを適切なページにリダイレクトしますが、3 番目のリダイレクトはまったく機能せず、ログイン ページに残るだけですが、ログイン機能から flash_success メッセージが表示されますか? ??
誰かが私を正しい方向に向けることができますか?
前もって感謝します
* Tim から要求された情報を追加*
フィルターおよびログイン機能の前のユーザーコントローラー:
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');
}
}