Class: Admin::OtpsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin/otps_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#admin_userObject (readonly)

Returns the value of attribute admin_user.



7
8
9
# File 'app/controllers/admin/otps_controller.rb', line 7

def admin_user
  @admin_user
end

Instance Method Details

#createObject



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

def create
  admin_user.otp_secret = otp_params[:otp_secret]

  if admin_user.otp.verify(otp_params[:token])
    admin_user.save

    redirect_to admin_admin_user_path(admin_user), status: :see_other
  else
    admin_user.errors.add(:token, :invalid)

    respond_to do |format|
      format.html { redirect_to admin_admin_user_path(admin_user), status: :see_other }
      format.turbo_stream { render locals: { admin_user: }, status: :unprocessable_content }
    end
  end
end

#destroyObject



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

def destroy
  admin_user.update!(otp_secret: nil)

  redirect_to admin_admin_user_path(admin_user), status: :see_other
end

#newObject



9
10
11
12
13
# File 'app/controllers/admin/otps_controller.rb', line 9

def new
  admin_user.otp_secret = ROTP::Base32.random

  render :new, locals: { admin_user: }
end