Module: Locomotive::API::Helpers::AuthenticationHelper
- Includes:
- Concerns::SiteDispatcherController
- Defined in:
- app/api/locomotive/api/helpers/authentication_helper.rb
Instance Method Summary collapse
- #authenticate_locomotive_account! ⇒ Object
- #current_account ⇒ Object
- #current_membership ⇒ Object
- #current_site ⇒ Object
- #pundit_user ⇒ Object
- #require_site! ⇒ Object
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_account ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/api/locomotive/api/helpers/authentication_helper.rb', line 8 def current_account @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_membership ⇒ Object
30 31 32 33 34 |
# File 'app/api/locomotive/api/helpers/authentication_helper.rb', line 30 def current_membership return nil if current_account.nil? membership = current_site ? current_site.membership_for(current_account) : nil membership || Locomotive::Membership.new(account: current_account) end |
#current_site ⇒ Object
21 22 23 |
# File 'app/api/locomotive/api/helpers/authentication_helper.rb', line 21 def current_site @current_site ||= env['locomotive.site'] end |
#pundit_user ⇒ Object
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 |