Class: Admin::SessionsController

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

Instance Method Summary collapse

Methods included from Koi::Controller::HasWebauthn

#webauthn_auth_options, #webauthn_authenticate!, #webauthn_relying_party

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/admin/sessions_controller.rb', line 16

def create
  if (admin_user = webauthn_authenticate! || params_authenticate!)
    record_sign_in!(admin_user)

    session[:admin_user_id] = admin_user.id

    redirect_to(url_from(params[:redirect].presence) || admin_dashboard_path, status: :see_other)
  else
    admin_user = Admin::User.new(session_params.slice(:email, :password))
    admin_user.errors.add(:email, "Invalid email or password")

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

#destroyObject



31
32
33
34
35
36
37
# File 'app/controllers/admin/sessions_controller.rb', line 31

def destroy
  record_sign_out!(current_admin_user)

  session[:admin_user_id] = nil

  redirect_to new_admin_session_path
end

#newObject



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

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