Sha256: e7d67a4b48457d4966daf4b4d396bfab659ea875f7b52da88f7527f480b0d177

Contents?: true

Size: 1.04 KB

Versions: 11

Compression:

Stored size: 1.04 KB

Contents

module Applicaster
  module AuthHelpers
    def current_user
      @current_user ||= user_from_session
    end

    def user_signed_in?
      !current_user.nil?
    end

    def authenticate_user!
      unless current_user
        store_location!
        redirect_to '/auth/applicaster'
      end
    end

    def current_access_token
      if credentials = session[:omniauth_credentials]
        credentials[:token] || credentials["token"]
      end
    end

    protected

    def store_location!
      session[:path_before_login] = if request.get?
                                      request.fullpath
                                    else
                                      request.referrer
                                    end
    end

    def clear_omniauth_credentials
      session.delete(:omniauth_credentials)
    end

    def user_from_session
      return nil unless current_access_token

      Applicaster::Accounts.user_from_token(current_access_token).tap do |user|
        clear_omniauth_credentials unless user
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
omniauth-applicaster-1.8.0 lib/applicaster/auth_helpers.rb
omniauth-applicaster-1.7.1 lib/applicaster/auth_helpers.rb
omniauth-applicaster-1.7.0 lib/applicaster/auth_helpers.rb
omniauth-applicaster-1.6.1 lib/applicaster/auth_helpers.rb
omniauth-applicaster-1.6.0 lib/applicaster/auth_helpers.rb
omniauth-applicaster-1.5.2 lib/applicaster/auth_helpers.rb
omniauth-applicaster-1.5.1 lib/applicaster/auth_helpers.rb
omniauth-applicaster-1.5.0 lib/applicaster/auth_helpers.rb
omniauth-applicaster-1.4.0 lib/applicaster/auth_helpers.rb
omniauth-applicaster-1.3.5 lib/applicaster/auth_helpers.rb
omniauth-applicaster-1.3.4 lib/applicaster/auth_helpers.rb