class Locomotive::Steam::Liquid::Tags::Authorize
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' %}
Constants
- Syntax
Public Class Methods
new(tag_name, markup, options)
click to toggle source
Calls superclass method
# File lib/locomotive/steam/liquid/tags/authorize.rb, line 28 def initialize(tag_name, markup, options) 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
Public Instance Methods
render(context)
click to toggle source
# 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
Private Instance Methods
locale()
click to toggle source
# File lib/locomotive/steam/liquid/tags/authorize.rb, line 50 def locale @context.registers[:locale] end
services()
click to toggle source
# File lib/locomotive/steam/liquid/tags/authorize.rb, line 54 def services @context.registers[:services] end