2013-06-18 97 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的用户根本不被允许做任何事情,甚至没有登录,所以他们被重定向到登录视图,创建一个无限循环。