Sha256: 432273f426db9ad56c9886a401d782ff50d990d901808e6218ee337f3e0e9fae

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module RailsBase::Mfa::Register
  class TotpController < RailsBaseApplicationController
    before_action :authenticate_user!

    # DELETE mfa/register/totp
    def totp_remove
      result = RailsBase::Mfa::Totp::Remove.(password: params[:password], user: current_user, otp_code: params[:totp_code])

      if result.success?
        flash[:notice] = "Successfully Removed TOTP Authentication to #{RailsBase.app_name}"
      else
        flash[:alert] = "Something Went Wrong! #{result.message}"
      end

      redirect_to RailsBase.url_routes.user_settings_path
    end

    # POST mfa/register/totp
    def totp_secret
      result = RailsBase::Mfa::Totp::OtpMetadata.(user: current_user)
      if result.success?
        render json: result.metadata
      else
        render json: { status: result.message }, status: 400
      end
    end

    # POST mfa/register/totp/validate
    def totp_validate
      result = RailsBase::Mfa::Totp::ValidateTemporaryCode.(user: current_user, otp_code: params[:totp_code])
      if result.success?
        flash[:notice] = "Successfully added an Authenticator for TOTP to #{RailsBase.app_name}"
      else
        flash[:alert] = "Something Went Wrong! Failed to add an Authenticator for TOTP to #{RailsBase.app_name}. Please try again"
      end

      redirect_to RailsBase.url_routes.user_settings_path
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_base-0.82.0 app/controllers/rails_base/mfa/register/totp_controller.rb
rails_base-0.81.1 app/controllers/rails_base/mfa/register/totp_controller.rb
rails_base-0.81.0 app/controllers/rails_base/mfa/register/totp_controller.rb
rails_base-0.80.0 app/controllers/rails_base/mfa/register/totp_controller.rb