Sha256: 93ee5b48339a6daaad8a16d0a8196aed300c14c9ebd496db372c97566296e3b4

Contents?: true

Size: 1.1 KB

Versions: 23

Compression:

Stored size: 1.1 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 ||= request.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

23 entries across 23 versions & 1 rubygems

Version Path
locomotivecms-3.3.0 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.3.0.rc3 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.3.0.rc2 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.1.2 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.2.1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.3.0.rc1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.2.0 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.2.0.rc2 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.2.0.rc1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.1.1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.1.0 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.1.0.rc3 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.1.0.rc2 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.1.0.rc1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.0.1 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.0.0 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.0.0.rc7 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.0.0.rc6 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.0.0.rc5 app/api/locomotive/api/helpers/authentication_helper.rb
locomotivecms-3.0.0.rc4 app/api/locomotive/api/helpers/authentication_helper.rb