0

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

我发现 Auth 组件中的 userScope 可以做到这一点。因此,在beforeFilter内的AppController中,我添加了以下内容:

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

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

但是,这无济于事,我仍然可以使用活动设置为 0 的用户登录。我认为这可能是因为 ACL 组件?

这是我在 AppController 中的 beforFilter

    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);
    }

我错过了什么?

4

2 回答 2

2

如果你不成功,你可以随时使用替代方案:

$user = $this->Auth->user();
if($user['User']['active'] == 0){
   $this->redirect($this->Auth->logout());
   $this->Session->setFlash('You are not active.');
}
于 2012-09-06T14:26:40.290 回答
1

您使用的代码对 Cake 2 无效。请参阅http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#configuring-authentication-handlers

这是一些应该可以工作的代码:

$this->Auth->authenticate = array('Form' => array('scope' => array('User.active' => 1)));
于 2012-09-06T20:37:04.007 回答