2013-06-18 100 views
1

我有兩個用戶組。當我用管理員用戶登錄時,它可以正常工作,但是當我嘗試從另一個用戶組登錄時,我得到一個無限循環。 這是我使用的代碼:CakePHP - 無限循環登錄

UsersController.php:

public function login() { 
if ($this->Session->read('Auth.User')) { 
    $this->Session->setFlash('You are logged in!'); 
    $this->redirect('/pwds', null, false); 
    } 
else 
     if ($this->request->is('post')) { 
      if ($this->Auth->login()) { 
        $this->redirect($this->Auth->redirect()); 
      } else { 
       $this->Session->setFlash('Your username or password was incorrect.'); 
      } 
     } 
} 

public function logout() { 
$this->Session->setFlash('Good-Bye'); 
$this->redirect($this->Auth->logout()); 
} 

public function beforeFilter() { 
parent::beforeFilter(); 
//$this->Auth->allow('index', 'view'); 
} 

AppController.php:

public function beforeFilter() { 
    //Configure AuthComponent 

$this->Auth->allow('display'); 
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); 
    $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login'); 
    $this->Auth->loginRedirect = array('controller' => 'pwds', 'action' => 'index'); 
} 

謝謝

回答

0

我剛剛發現了這個問題。 NonAdmins的用戶根本不被允許做任何事情,甚至沒有登錄,所以他們被重定向到登錄視圖,創建一個無限循環。