Sha256: 3499cb294516cf032bf386e223c0dba5878bc77744f164b6133c092ddf910963

Contents?: true

Size: 764 Bytes

Versions: 2

Compression:

Stored size: 764 Bytes

Contents

# Contains authentication logic to check the user has been authenticated,
# and that the session hasn't expired.
module Balrog::Guard
  def authenticated?(balrog_session)
    @balrog_session = balrog_session
    previously_authenticated? && still_valid?
  end

  private

  # A method to check that the user has been authenticated before.
  def previously_authenticated?
    return false unless @balrog_session
    @balrog_session['value'] == 'authenticated'
  end

  # A method to check that the authentication has not expired.
  def still_valid?
    # If the user did not set configured the Balrog session 
    # to expire, the cookie is valid.
    return true unless @balrog_session['expiry_date']
    DateTime.current < @balrog_session['expiry_date']
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
balrog-2.0.0 lib/balrog/guard.rb
balrog-1.1.0 lib/balrog/guard.rb