two_factor_authentication_methods_controller.rb 748 B

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