dongyi1015 2012-09-06 13:30
浏览 48
已采纳

在CakePHP中使用条件的Auth和ACL

I can't find a solution to my problem. I have an CakePHP website using Auth Component and ACL component. I do not want users who are not active to be able to log in.

I found that userScope in Auth component can do that. So in my AppController inside the beforeFilter, i added this :

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

Of course in my UserController beforeFilter, a call to the parent method is made.

However, this doesn't worj, I am still able to login in with a user who have active set to 0. I think it might be because of ACL component ?

Here is my beforFilter in 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);
    }

What am I missing ?

  • 写回答

2条回答 默认 最新

  • duanlei4759 2012-09-06 20:37
    关注

    The code you use is not valid with Cake 2. See http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#configuring-authentication-handlers

    Here is some code that should work:

    $this->Auth->authenticate = array('Form' => array('scope' => array('User.active' => 1)));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?