verify_method_configuration.rb 938 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::User::TwoFactor::VerifyMethodConfiguration < Service::User::TwoFactor::Base
  3. attr_reader :payload, :configuration
  4. def initialize(configuration:, payload:, **)
  5. super(**)
  6. @configuration = configuration
  7. @payload = payload
  8. end
  9. def execute
  10. if !method&.enabled? || !method&.available?
  11. raise Exceptions::UnprocessableEntity, __('The two-factor authentication method is not enabled.')
  12. end
  13. verified = user.two_factor_verify_configuration?(method_name, payload, configuration)
  14. if !verified
  15. raise Service::User::TwoFactor::VerifyMethodConfiguration::Failed, __('The verification of the two-factor authentication method configuration failed.')
  16. end
  17. {
  18. recovery_codes: Service::User::TwoFactor::GenerateRecoveryCodes.new(user: user).execute
  19. }
  20. end
  21. class Failed < StandardError; end
  22. end