two_factor_authentication_methods_controller.rb 761 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. module Settings
  3. class TwoFactorAuthenticationMethodsController < BaseController
  4. include ChallengableConcern
  5. layout 'admin'
  6. before_action :authenticate_user!
  7. before_action :require_challenge!, only: :disable
  8. before_action :require_otp_enabled
  9. skip_before_action :require_functional!
  10. def index; end
  11. def disable
  12. current_user.disable_two_factor!
  13. UserMailer.two_factor_disabled(current_user).deliver_later!
  14. redirect_to settings_otp_authentication_path, flash: { notice: I18n.t('two_factor_authentication.disabled_success') }
  15. end
  16. private
  17. def require_otp_enabled
  18. redirect_to settings_otp_authentication_path unless current_user.otp_enabled?
  19. end
  20. end
  21. end