You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
748 B

  1. # frozen_string_literal: true
  2. module Settings
  3. class TwoFactorAuthenticationsController < ApplicationController
  4. layout 'admin'
  5. before_action :authenticate_user!
  6. before_action :verify_otp_required, only: [:create]
  7. def show; end
  8. def create
  9. current_user.otp_secret = User.generate_otp_secret(32)
  10. current_user.save!
  11. redirect_to new_settings_two_factor_authentication_confirmation_path
  12. end
  13. def destroy
  14. current_user.otp_required_for_login = false
  15. current_user.save!
  16. redirect_to settings_two_factor_authentication_path
  17. end
  18. private
  19. def verify_otp_required
  20. redirect_to settings_two_factor_authentication_path if current_user.otp_required_for_login?
  21. end
  22. end
  23. end