Resque,Devise和admin认证 [英] Resque, Devise and admin authentication

查看:129
本文介绍了Resque,Devise和admin认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Resque and Devise,我有用户角色,如:

  User.first.role#=> admin 
User.last.role#=>常规

我想为Resque设置身份验证。所以,在config / routes.rb里面我有:

 命名空间:admin do 
mount Resque :: Server.new ,:at => / resque,:as => :resque
end

当然,所有登录用户都可以访问。 p>

有没有办法从User.role使用角色?只能由具有admin角色的用户访问。



非常感谢。

解决方案

routes.rb 文件中使用路由约束:

  resque_constraint = lambda do | request | 
request.env ['warden']。authenticate?和request.env ['warden']。user.admin?
end

约束resque_constraint do
mount Resque :: Server,:at => / admin / resque
end

看到这个博客文章和评论。希望它可以帮助你。


Using Resque and Devise, i have roles for User, like:

User.first.role #=> admin
User.last.role #=> regular

I want to setup an authentication for Resque. So, inside config/routes.rb i have:

namespace :admin do
  mount Resque::Server.new, :at => "/resque", :as => :resque
end

And, of course it's accessible for all logged in users.

Is there any way to use a role from User.role? It should be accessible only by users with 'admin' role.

Thanks a lot.

解决方案

Use a route constraint, in your routes.rb file:

  resque_constraint = lambda do |request|
    request.env['warden'].authenticate? and request.env['warden'].user.admin?
  end

  constraints resque_constraint do
    mount Resque::Server, :at => "/admin/resque"
  end

See this blog post and the comments. Hope it helps you.

这篇关于Resque,Devise和admin认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆