简体   繁体   English

使用水银轨道进行认证

[英]authentication with mercury-rails

How do you add authentication checks on the /editor/.* routes in Mercury via the mercury-rails gem? 如何通过mercury-rails gem在Mercury的/editor/.*路由上添加身份验证检查?

I mean, I know you can: 我的意思是,我知道你可以:

  • hide the link to the editor when not authenticated. 未经过身份验证时隐藏指向编辑器的链接。
  • refuse updates from the editor when not authenticated. 未经过身份验证时拒绝编辑器的更新。

But I'd prefer the user be kicked out of the editor incase he/she has a bookmark to the editor and isn't logged in. 但是我希望用户被踢出编辑器,因为他/她有一个书签给编辑器但没有登录。

PS: Can someone create a mercury-editor tag for this? PS:有人可以为此创建一个mercury-editor标签吗? Otherwise searching for mercury-editor is neigh impossible. 否则,搜索水银编辑器几乎是不可能的。

A before_filter method is probably what you would want to use. before_filter方法可能就是您想要使用的方法。

You could just add your own controller than inherits from the MercuryController and point the routes to your controller: 您可以添加自己的控制器,而不是从MercuryController继承,并将路由指向您的控制器:

In config/routes.rb: 在config / routes.rb中:

...
match '/editor(/*requested_uri)' => "my_mercury#edit", :as => :mercury_editor
Mercury::Engine.routes
...

And app/controllers/my_mercury_controller.rb 和app / controllers / my_mercury_controller.rb

class MyMercuryController < MercuryController
    before_filter :login_required
    def login_required
        ...
    end
end

Looks like now the mercury-rails installer will ask you if you want them to add some authentication code, and if you do it creates 现在看来,如果你想让他们想要添加一些身份验证代码,那么他们会问你是否会创建

lib/mercury/authentication.rb LIB /汞/ authentication.rb

module Mercury
  module Authentication

    def can_edit?
      true # check here to see if the user is logged in/has access
    end
  end
end

Where you can run your check code in there. 你可以在那里运行你的支票代码。 Maybe something like "if user_signed_in? && current_user.admin?" 也许像“if user_signed_in?&& current_user.admin?”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM