Mercury Rail Authentication

How to add authentication on /editor/.* routes in Mercury using mercury-rails gem?

I mean, I know that you can:

  • hide the link to the editor if it is not authenticated.
  • refuse updates from the editor in the absence of authentication.

But I would prefer that the user be kicked out of the editor if he has a bookmark in the editor and is not logged in.

PS: Can anyone create a mercury-editor tag for this? Otherwise, the search for the mercury editor is not possible.

+6
source share
2 answers

It looks like now the mercury-rails installer will ask you if you want to add an authentication code, and if you do, create

Library / mercury / 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. Maybe something like "if user_signed_in? && current_user.admin?"

+3
source

The before_filter method is probably what you want to use.

You can simply add your own controller than inherit from MercuryController, and specify the routes to your controller:

In config / routes.rb:

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

And application / controllers / my_mercury_controller.rb

 class MyMercuryController < MercuryController before_filter :login_required def login_required ... end end 
+7
source

Source: https://habr.com/ru/post/901082/


All Articles