Class: Admin::SessionsController

Inherits:
ApplicationController show all
Includes:
Koi::Controller::HasWebauthn, Koi::Controller::RecordsAuthentication
Defined in:
app/controllers/admin/sessions_controller.rb

Instance Method Summary collapse

Methods included from Koi::Controller::RecordsAuthentication

#record_sign_in!, #record_sign_out!, #update_last_sign_in

Methods included from Koi::Controller::HasWebauthn

#webauthn_auth_options, #webauthn_authenticate!, #webauthn_relying_party

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/admin/sessions_controller.rb', line 17

def create
  if session_params[:response].present?
    create_session_with_webauthn
  elsif session_params[:token].present?
    create_session_with_token
  elsif session_params[:password].present?
    create_session_with_password
  elsif session_params[:email].present?
    # conversational flow, ask for password regardless of email
    admin_user = Admin::User.new(session_params.slice(:email))

    render(:password, status: :unprocessable_content, locals: { admin_user: })
  else
    # invalid request, re-render new
    admin_user = Admin::User.new

    render(:new, status: :unprocessable_content, locals: { admin_user: })
  end
end

#destroyObject



37
38
39
40
41
42
43
# File 'app/controllers/admin/sessions_controller.rb', line 37

def destroy
  record_sign_out!(current_admin_user)

  session[:admin_user_id] = nil

  redirect_to new_admin_session_path
end

#newObject



13
14
15
# File 'app/controllers/admin/sessions_controller.rb', line 13

def new
  render locals: { admin_user: Admin::User.new }
end