about summary refs log tree commit diff
path: root/app/controllers/settings/two_factor_authentication/recovery_codes_controller.rb
blob: 0c4f5bff762c591c8c4d14f56de5671edbffc0d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module Settings
  module TwoFactorAuthentication
    class RecoveryCodesController < BaseController
      include ChallengableConcern

      layout 'admin'

      before_action :authenticate_user!
      before_action :require_challenge!, on: :create

      skip_before_action :require_functional!

      def create
        @recovery_codes = current_user.generate_otp_backup_codes!
        current_user.save!

        UserMailer.two_factor_recovery_codes_changed(current_user).deliver_later!
        flash.now[:notice] = I18n.t('two_factor_authentication.recovery_codes_regenerated')

        render :index
      end
    end
  end
end