Module: Locomotive::API::Helpers::AuthenticationHelper

Includes:
Concerns::SiteDispatcherController
Defined in:
app/api/locomotive/api/helpers/authentication_helper.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_locomotive_account!Object



16
17
18
19
# File 'app/api/locomotive/api/helpers/authentication_helper.rb', line 16

def authenticate_locomotive_account!
  error!('Unauthorized', 401) unless current_membership
  true
end

#current_accountObject



8
9
10
11
12
13
14
# File 'app/api/locomotive/api/helpers/authentication_helper.rb', line 8

def 
  @current_user ||= begin
    token = headers['X-Locomotive-Account-Token']
    email = headers['X-Locomotive-Account-Email']
    Account.where(email: email, authentication_token: token).first
  end
end

#current_membershipObject



30
31
32
33
34
# File 'app/api/locomotive/api/helpers/authentication_helper.rb', line 30

def current_membership
  return nil if .nil?
  membership = current_site ? current_site.membership_for() : nil
  membership || Locomotive::Membership.new(account: )
end

#current_siteObject



21
22
23
# File 'app/api/locomotive/api/helpers/authentication_helper.rb', line 21

def current_site
  @current_site ||= env['locomotive.site']
end

#pundit_userObject



36
37
38
# File 'app/api/locomotive/api/helpers/authentication_helper.rb', line 36

def pundit_user
  current_membership
end

#require_site!Object



25
26
27
28
# File 'app/api/locomotive/api/helpers/authentication_helper.rb', line 25

def require_site!
  error!('Unknown site', 404) unless current_site
  true
end