簡體   English   中英

使用水銀軌道進行認證

[英]authentication with mercury-rails

如何通過mercury-rails gem在Mercury的/editor/.*路由上添加身份驗證檢查?

我的意思是,我知道你可以:

  • 未經過身份驗證時隱藏指向編輯器的鏈接。
  • 未經過身份驗證時拒絕編輯器的更新。

但是我希望用戶被踢出編輯器,因為他/她有一個書簽給編輯器但沒有登錄。

PS:有人可以為此創建一個mercury-editor標簽嗎? 否則,搜索水銀編輯器幾乎是不可能的。

before_filter方法可能就是您想要使用的方法。

您可以添加自己的控制器,而不是從MercuryController繼承,並將路由指向您的控制器:

在config / routes.rb中:

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

和app / controllers / my_mercury_controller.rb

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

現在看來,如果你想讓他們想要添加一些身份驗證代碼,那么他們會問你是否會創建

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

你可以在那里運行你的支票代碼。 也許像“if user_signed_in?&& current_user.admin?”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM