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



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

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

    session[:admin_user_id] = admin_user.id

    redirect_to admin_dashboard_path, notice: I18n.t("koi.auth.login")
  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



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

def destroy
  record_sign_out!(current_admin_user)

  session[:admin_user_id] = nil

  redirect_to admin_dashboard_path, notice: I18n.t("koi.auth.logout")
end

#newObject



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

def new
  return redirect_to admin_dashboard_path if admin_signed_in?

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