admin_password_auth_send.rb 901 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class AdminPasswordAuthSend < BaseMutation
  4. include Gql::Concerns::HandlesThrottling
  5. description 'Sends an email with a token to login via password.'
  6. argument :login, String, 'Login information that is used to create a token.'
  7. field :success, Boolean, null: true, description: 'This indicates if sending the token was successful.'
  8. def self.authorize(...)
  9. true
  10. end
  11. def ready?(login:)
  12. throttle!(limit: 3, period: 1.minute, by_identifier: login)
  13. end
  14. def resolve(login:)
  15. send = Service::Auth::SendAdminToken.new(login: login)
  16. begin
  17. send.execute
  18. rescue Service::Auth::SendAdminToken::TokenError, Service::Auth::SendAdminToken::EmailError
  19. return { success: false }
  20. end
  21. { success: true }
  22. end
  23. end
  24. end