2012-09-06 104 views
0

我无法找到解决我的问题的方法。 我有一个使用Auth组件和ACL组件的CakePHP网站。 我不希望不活动的用户能够登录。Auth和ACL在CakePHP中有条件

我发现user身份验证组件可以做到这一点。 所以在我AppController中beforeFilter里面,我添加了这个:

$this->Auth->userScope = array('User.active' => 1); 

当然,在我的UserController的beforeFilter,父方法的调用。

但是,这并不worj,我仍然能够登录与积极设置为0的用户。 我认为这可能是因为ACL组件?

这是我在beforFilter AppController的

public function beforeFilter() 
    { 
    if (!$this->Session->check('Auth.User')) 
     $this->layout = 'identification'; 
    $this->Auth->allow('display'); 

    //Configure AuthComponent 
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); 
    $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login'); 
    $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'welcome'); 
    $this->Auth->userScope = array('User.active' => 1); 
    } 

我缺少什么?

+0

U是否使用cakePHP 2.0或1.3? –

+0

我正在使用CakePHP 2.0 – azerto00

回答

2

如果你不做,你总是可以使用一种替代方案:

$user = $this->Auth->user(); 
if($user['User']['active'] == 0){ 
    $this->redirect($this->Auth->logout()); 
    $this->Session->setFlash('You are not active.'); 
} 
+0

好的,我在$ this-> Auth-> login()方法后执行了检查,如果用户不活动,调用$ this-> Auth-> logout()并且重定向到一个好的布局。但它不太好,因为我需要登录用户登录用户。不是很好的安全... – azerto00

+0

我知道,但这是目前最好的拍摄,直到你找到一个更好的解决方案,如果你找到它,随时张贴在这里。 :D – 2012-09-06 15:05:17