Class: Booth::Requests::Storages::Login

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/booth/requests/storages/login.rb

Instance Method Summary collapse

Constructor Details

#initialize(session:) ⇒ Login

Returns a new instance of Login.



9
10
11
# File 'lib/booth/requests/storages/login.rb', line 9

def initialize(session:)
  @session = session
end

Instance Method Details

#contest_for_usernameObject



27
28
29
30
31
# File 'lib/booth/requests/storages/login.rb', line 27

def contest_for_username
  return @contest_for_username if defined?(@contest_for_username)

  @contest_for_username = ::Booth::Models::Contest.find_by(id: session[:contest_for_username])
end

#contest_for_username=(new_contest) ⇒ Object



63
64
65
66
67
# File 'lib/booth/requests/storages/login.rb', line 63

def contest_for_username=(new_contest)
  debug { "Persisting contest for username in browser session for scope #{scope.inspect}" }
  session[:contest_for_username] = new_contest.id
  @contest_for_username = nil
end

#credential_for_usernameObject



21
22
23
24
25
# File 'lib/booth/requests/storages/login.rb', line 21

def credential_for_username
  return @credential_for_username if defined?(@credential_for_username)

  @credential_for_username = ::Booth::Models::Credential.find_by(id: session[:credential_for_username])
end

#credential_for_username=(new_credential) ⇒ Object



57
58
59
60
61
# File 'lib/booth/requests/storages/login.rb', line 57

def credential_for_username=(new_credential)
  debug { "Persisting credential for username in browser session for scope #{scope.inspect}" }
  session[:credential_for_username] = new_credential.id
  @credential_for_username = nil
end

#password_authenticated_credentialObject



33
34
35
36
37
38
39
# File 'lib/booth/requests/storages/login.rb', line 33

def password_authenticated_credential
  return @password_authenticated_credential if defined?(@password_authenticated_credential)

  @password_authenticated_credential = ::Booth::Models::Credential.find_by(
    id: session[:password_authenticated_credential]
  )
end

#password_authenticated_credential=(new_credential) ⇒ Object



75
76
77
78
79
# File 'lib/booth/requests/storages/login.rb', line 75

def password_authenticated_credential=(new_credential)
  debug { "Persisting password authenticated credential in browser session for scope #{scope.inspect}" }
  session[:password_authenticated_credential] = new_credential.id
  @password_authenticated_credential = nil
end

#reset_credential_for_usernameObject



69
70
71
72
73
# File 'lib/booth/requests/storages/login.rb', line 69

def reset_credential_for_username
  debug { "Resetting credential in browser session for scope #{scope.inspect}" }
  session.delete(:credential_for_username)
  @credential_for_username = nil
end

#reset_remotesObject



96
97
98
# File 'lib/booth/requests/storages/login.rb', line 96

def reset_remotes
  session.delete(:skip_remotes)
end

#skip_remotesObject



92
93
94
# File 'lib/booth/requests/storages/login.rb', line 92

def skip_remotes
  session[:skip_remotes] = true
end

#skip_remotes?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/booth/requests/storages/login.rb', line 45

def skip_remotes?
  session[:skip_remotes].present?
end

#usernameObject


Getters




17
18
19
# File 'lib/booth/requests/storages/login.rb', line 17

def username
  session[:username]
end

#username=(new_username) ⇒ Object


Setters




53
54
55
# File 'lib/booth/requests/storages/login.rb', line 53

def username=(new_username)
  session[:username] = new_username
end

#webauthn_challengeObject



41
42
43
# File 'lib/booth/requests/storages/login.rb', line 41

def webauthn_challenge
  session[:webauthn_challenge].presence
end

#webauthn_challenge=(new_challenge) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/booth/requests/storages/login.rb', line 81

def webauthn_challenge=(new_challenge)
  if new_challenge
    debug do
      "Persisting webauth challenge #{new_challenge.inspect} in browser session for scope #{scope.inspect}"
    end
  else
    debug { "Removing webauth challenge from browser session for scope #{scope.inspect}" }
  end
  session[:webauthn_challenge] = new_challenge.presence
end