Resque、Devise 和管理员身份验证 [英] Resque, Devise and admin authentication

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

问题描述

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

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

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

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

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.

有没有办法使用 User.role 中的角色?它应该只能由具有管理员"角色的用户访问.

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

非常感谢.

推荐答案

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

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

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

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