Module: Veri::Authentication

Extended by:
ActiveSupport::Concern
Defined in:
lib/veri/controllers/concerns/authentication.rb

Instance Method Summary collapse

Instance Method Details

#current_sessionObject



29
30
31
32
33
# File 'lib/veri/controllers/concerns/authentication.rb', line 29

def current_session
  token = cookies.encrypted["veri_token"]

  @current_session ||= Session.find_active(token, resolved_tenant)
end

#current_userObject



25
26
27
# File 'lib/veri/controllers/concerns/authentication.rb', line 25

def current_user
  @current_user ||= current_session&.authenticatable
end

#log_in(authenticatable) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/veri/controllers/concerns/authentication.rb', line 35

def (authenticatable)
  processed_authenticatable = Veri::Inputs::Authenticatable.new(
    authenticatable,
    message: "Expected an instance of #{Veri::Configuration.user_model_name}, got `#{authenticatable.inspect}`"
  ).process

  return false if processed_authenticatable.locked?

  token = Veri::Session.establish(processed_authenticatable, request, resolved_tenant)

  cookies.encrypted.permanent["veri_token"] = { value: token, httponly: true, secure: request.ssl? }
  reset_memoization
  true
end

#log_outObject



50
51
52
53
54
# File 'lib/veri/controllers/concerns/authentication.rb', line 50

def log_out
  current_session&.terminate
  cookies.delete("veri_token")
  reset_memoization
end

#logged_in?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/veri/controllers/concerns/authentication.rb', line 56

def logged_in?
  current_user.present?
end

#return_pathObject



60
61
62
# File 'lib/veri/controllers/concerns/authentication.rb', line 60

def return_path
  cookies.signed["veri_return_path"]
end

#shapeshifter?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/veri/controllers/concerns/authentication.rb', line 64

def shapeshifter?
  !!current_session&.shapeshifted?
end