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
31
32
33
34
35
36
# File 'app/controllers/admin/sessions_controller.rb', line 17

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

    session[:admin_user_id] = admin_user.id

    redirect_to admin_dashboard_path, notice: "You have been logged in"
  elsif (admin_user = Admin::User.authenticate_by(session_params.slice(:email, :password)))
    record_sign_in!(admin_user)

    session[:admin_user_id] = admin_user.id

    redirect_to admin_dashboard_path, notice: "You have been logged in"
  else
    admin_user = Admin::User.new(session_params.slice(:email, :password))
    admin_user.errors.add(:email, "Invalid email or password")

    render :new, status: :unprocessable_entity, locals: { admin_user: }
  end
end

#destroyObject



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

def destroy
  record_sign_out!(current_admin_user)

  session[:admin_user_id] = nil

  redirect_to admin_dashboard_path, notice: "You have been logged out"
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