Class: Admin::CredentialsController

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Koi::Controller::HasWebauthn

#webauthn_authenticate!, #webauthn_nickname, #webauthn_register!, #webauthn_relying_party

Instance Attribute Details

#admin_userObject (readonly)

Returns the value of attribute admin_user.



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

def admin_user
  @admin_user
end

#credentialObject (readonly)

Returns the value of attribute credential.



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

def credential
  @credential
end

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
# File 'app/controllers/admin/credentials_controller.rb', line 23

def create
  webauthn_register!(credential_params[:response])

  if %r{/credentials/new$}.match?(request.referer)
    redirect_to(admin_root_path, status: :see_other)
  else
    redirect_back_or_to(admin_profile_path, status: :see_other)
  end
end

#destroyObject



41
42
43
44
45
# File 'app/controllers/admin/credentials_controller.rb', line 41

def destroy
  credential.destroy!

  redirect_to(admin_profile_path, status: :see_other)
end

#newObject



19
20
21
# File 'app/controllers/admin/credentials_controller.rb', line 19

def new
  render locals: { admin_user: }
end

#showObject



15
16
17
# File 'app/controllers/admin/credentials_controller.rb', line 15

def show
  render locals: { credential: }
end

#updateObject



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

def update
  if credential.update(credential_params)
    redirect_to(admin_profile_path, status: :see_other)
  else
    render :show, locals: { credential: }, status: :unprocessable_content
  end
end