Class: Locomotive::Steam::Liquid::Tags::Authorize
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Locomotive::Steam::Liquid::Tags::Authorize
- Defined in:
- lib/locomotive/steam/liquid/tags/authorize.rb
Overview
Redirect the current site visitor to another page if she/he is not authenticated. More information about the authentication feature here: locomotive-v3.readme.io/v3.3/docs/introduction-1
The Liquid tag requires 2 parameters:
-
the slug of the content type used for the authentication (a content type with a password field)
-
the handle of the page we want the user to be redirected to if unauthenticated
Basically the authorize tag checks if the liquid context has a reference to the current authenticated content entry. If not, it raises a redirection exception forcing the Steam middleware stack to process a HTTP redirection.
Example:
{% authorize 'accounts', 'sign_in' %}
Constant Summary collapse
Instance Method Summary collapse
-
#initialize(tag_name, markup, options) ⇒ Authorize
constructor
A new instance of Authorize.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, options) ⇒ Authorize
Returns a new instance of Authorize.
28 29 30 31 32 33 34 35 36 |
# File 'lib/locomotive/steam/liquid/tags/authorize.rb', line 28 def initialize(tag_name, markup, ) if markup =~ Syntax @content_type_slug, @page_handle = $1.try(:gsub, /['"]/, ''), $2.try(:gsub, /['"]/, '') else raise ::Liquid::SyntaxError.new("Syntax Error in 'authorize' - Valid syntax: authorize [content type slug], [page handle]") end super end |
Instance Method Details
#render(context) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/locomotive/steam/liquid/tags/authorize.rb', line 38 def render(context) @context = context unless authenticated_entry = context["current_#{@content_type_slug.singularize}"] services.page_redirection.redirect_to(@page_handle, locale) end '' end |