Class: Rails::Auth::MfaController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rails/auth/mfa_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/rails/auth/mfa_controller.rb', line 9

def create
  if current_user.verify_otp(params[:otp_code])
    current_user.update(otp_enabled: true)
    redirect_to security_sessions_path, notice: "Two-factor authentication enabled."
  else
    flash.now[:alert] = "Invalid OTP code. Please try again."
    @qrcode = RQRCode::QRCode.new(current_user.otp_provisioning_uri)
    render :show, status: :unprocessable_entity
  end
end

#destroyObject



20
21
22
23
# File 'app/controllers/rails/auth/mfa_controller.rb', line 20

def destroy
  current_user.update(otp_enabled: false, otp_secret: nil)
  redirect_to security_sessions_path, notice: "Two-factor authentication disabled."
end

#showObject



4
5
6
7
# File 'app/controllers/rails/auth/mfa_controller.rb', line 4

def show
  current_user.generate_otp_secret! unless current_user.otp_secret
  @qrcode = RQRCode::QRCode.new(current_user.otp_provisioning_uri)
end