【问题标题】:Authenticate rails_admin with admin attribute使用 admin 属性验证 rails_admin
【发布时间】:2016-10-16 22:14:02
【问题描述】:

我希望能够让 admin 属性设置为 true 的用户访问 rails_admin。因此,如果用户的 is_admin 属性为 true,则他们可以访问 rails_admin 界面。

我已经检查了他们的文档,我能找到的关于身份验证的所有信息都在这里:https://github.com/sferik/rails_admin/wiki/Authentication

拜托,你能帮我做吗?

谢谢

【问题讨论】:

    标签: ruby-on-rails rails-admin


    【解决方案1】:

    来自https://github.com/sferik/rails_admin/wiki/Authorization

    config.authorize_with do
      redirect_to main_app.root_path unless current_user.is_admin?
    end
    

    【讨论】:

      【解决方案2】:

      文档已经解释了,你必须做什么:

      在您的 rails_admin.rb 初始化程序中:

      config.authenticate_with do
        warden.authenticate! :scope => :admin
      end
      config.current_user_method { current_admin } # hook to your 'current_user' method
      

      在你的用户模型中你生成 current_admin 方法:

      def current_admin
        current_user && current_user.is_admin
      end
      

      我认为这应该可行。

      【讨论】:

      • Matherick 这个warden.authenticate 是做什么的! :scope => :admin 是什么意思?
      • 也许这回答了你的问题:github.com/hassox/warden/wiki/Scopes。您可以将 rails_admin 配置为使用warden 身份验证。
      猜你喜欢
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 2021-05-15
      • 2012-08-03
      • 1970-01-01
      相关资源
      最近更新 更多