generate_recovery_codes.rb 483 B

12345678910111213141516171819
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::User::TwoFactor::GenerateRecoveryCodes < Service::Base
  3. attr_reader :user, :force
  4. def initialize(user:, force: false)
  5. super()
  6. @user = user
  7. @force = force
  8. end
  9. def execute
  10. return if !user.auth_two_factor.recovery_codes_enabled?
  11. return if user.auth_two_factor.user_recovery_codes_exists? && !force
  12. Auth::TwoFactor::RecoveryCodes.new(user).generate
  13. end
  14. end