Sha256: e86f7b7d9987603a3e9218fcaf9f4864ca0b52b6ef3c4529b03c5738aa53b275

Contents?: true

Size: 1.09 KB

Versions: 15

Compression:

Stored size: 1.09 KB

Contents

module Locomotive
  module API
    module Helpers
      module AuthenticationHelper

        include Locomotive::Concerns::SiteDispatcherController

        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

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

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

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

        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

        def pundit_user
          current_membership
        end

      end

    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.2.0.alpha1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.1.1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.1.0 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.1.0.rc1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.0.3 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.0.2 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.0.1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.0.0 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.0.0.rc0 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.0.0.alpha3 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.4.1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.0.0.alpha2 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-4.0.0.alpha1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.4.0 app/api/locomotive/api/helpers/authentication_helper.rb