module Spree::Core::ControllerHelpers::Auth

Public Instance Methods

current_ability() click to toggle source

Needs to be overriden so that we use Spree's Ability rather than anyone else's.

# File lib/spree/core/controller_helpers/auth.rb, line 34
def current_ability
  @current_ability ||= Spree::Ability.new(try_spree_current_user)
end
redirect_back_or_default(default) click to toggle source
# File lib/spree/core/controller_helpers/auth.rb, line 38
def redirect_back_or_default(default)
  redirect_to(session["spree_user_return_to"] || default)
  session["spree_user_return_to"] = nil
end
set_guest_token() click to toggle source
# File lib/spree/core/controller_helpers/auth.rb, line 43
def set_guest_token
  unless cookies.signed[:guest_token].present?
    cookies.permanent.signed[:guest_token] = Spree::Config[:guest_token_cookie_options].merge(
      value: SecureRandom.urlsafe_base64(nil, false),
      httponly: true
    )
  end
end
store_location() click to toggle source
# File lib/spree/core/controller_helpers/auth.rb, line 52
def store_location
  Spree::UserLastUrlStorer.new(self).store_location
end
try_spree_current_user() click to toggle source

proxy method to possible spree_current_user method Authentication extensions (such as spree_auth_devise) are meant to provide spree_current_user

# File lib/spree/core/controller_helpers/auth.rb, line 58
def try_spree_current_user
  # This one will be defined by apps looking to hook into Spree
  # As per authentication_helpers.rb
  if respond_to?(:spree_current_user, true)
    spree_current_user
  # This one will be defined by Devise
  elsif respond_to?(:current_spree_user, true)
    current_spree_user
  end
end