acl9 和 devise 似乎不能很好地协同工作

发布于 2024-09-05 19:38:49 字数 765 浏览 4 评论 0原文

我有一个用户模型,其访问权限由 ACL9 控制。

UsersController中:

#ACL9 related stuff
before_filter :load_user, :only => [:show]
  access_control do
    allow :owner, :of => :user, :to => [:show]
  end

def load_user
  user = User.find(params[:id])
end

ApplicationController中:

rescue_from 'Acl9::AccessDenied', :with => :access_denied

def access_denied
  authenticate_user! # a method from Devise
end

输入登录页面的url没有问题http://localhost:3000/users/sign_in ,但是当我首先输入用户页面时,这是一个问题,我希望通过上面的逻辑将其重定向到自动登录页面。

http://localhost:3000/users/1 =>无限重定向地狱。它尝试再次重定向回 users/1,而不是定向到 users/sign_in

有人对可能出什么问题有意见吗?

I have a user model whose access controlled by ACL9.

in UsersController:

#ACL9 related stuff
before_filter :load_user, :only => [:show]
  access_control do
    allow :owner, :of => :user, :to => [:show]
  end

def load_user
  user = User.find(params[:id])
end

in ApplicationController:

rescue_from 'Acl9::AccessDenied', :with => :access_denied

def access_denied
  authenticate_user! # a method from Devise
end

It is no problem to type in url for sign in page http://localhost:3000/users/sign_in, but it is a problem when for example I type in the user page first, which I am to expect to be redirected to sign in page automatically through the logic above.

http://localhost:3000/users/1 => infinite redirect hell. It tries to redirect back to users/1 again instead of directing to users/sign_in.

Does anyone have an opinion as to what might be going wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回眸一遍 2024-09-12 19:38:49

我认为你不应该在 Devise 用户控制器中使用 Acl9。由于您没有经过身份验证,因此您没有任何权利,也不会进行身份验证:D。
您可能想禁止用户删除,所以它应该是这样的:

access_control :only => [:destroy] do
      allow :admin
end

对于 UsersController,如果您想将其保留在应用程序控制器中,则应该覆盖您的 access_control。

I think you should not use Acl9 in Devise user controller. Since you are not authenticated you have no rights and you will not authenticate :D.
You may want to forbid users to delete, so it should be like:

access_control :only => [:destroy] do
      allow :admin
end

For UsersController you should overwrite your access_control if you want to leave it as is in application controller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文