base.rb 685 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::User::TwoFactor::Base < Service::Base
  3. attr_reader :user, :method_name
  4. def initialize(user:, method_name:)
  5. super()
  6. @user = user
  7. @method_name = method_name
  8. return if method
  9. raise Exceptions::UnprocessableEntity, __('The given two-factor method does not exist.')
  10. end
  11. protected
  12. def method
  13. @method ||= user
  14. .auth_two_factor
  15. .authentication_method_object(method_name)
  16. end
  17. def method_available?
  18. method&.enabled? && method.available?
  19. end
  20. def user_preference
  21. @user_preference ||= method&.user_two_factor_preference
  22. end
  23. end