闭社主体 forked from https://github.com/tootsuite/mastodon
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.

43 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. module Settings
  3. module TwoFactorAuthentication
  4. class ConfirmationsController < ApplicationController
  5. layout 'admin'
  6. before_action :authenticate_user!
  7. def new
  8. prepare_two_factor_form
  9. end
  10. def create
  11. if current_user.validate_and_consume_otp!(confirmation_params[:code])
  12. flash[:notice] = I18n.t('two_factor_authentication.enabled_success')
  13. current_user.otp_required_for_login = true
  14. @recovery_codes = current_user.generate_otp_backup_codes!
  15. current_user.save!
  16. render 'settings/two_factor_authentication/recovery_codes/index'
  17. else
  18. flash.now[:alert] = I18n.t('two_factor_authentication.wrong_code')
  19. prepare_two_factor_form
  20. render :new
  21. end
  22. end
  23. private
  24. def confirmation_params
  25. params.require(:form_two_factor_confirmation).permit(:code)
  26. end
  27. def prepare_two_factor_form
  28. @confirmation = Form::TwoFactorConfirmation.new
  29. @provision_url = current_user.otp_provisioning_uri(current_user.email, issuer: Rails.configuration.x.local_domain)
  30. @qrcode = RQRCode::QRCode.new(@provision_url)
  31. end
  32. end
  33. end
  34. end