send.rb 945 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # frozen_string_literal: true
  3. module Gql::Mutations
  4. class User::PasswordReset::Send < BaseMutation
  5. include Gql::Concerns::HandlesThrottling
  6. description 'Send password reset link to the user.'
  7. argument :username, String, required: true, description: 'The user login or email'
  8. field :success, Boolean, description: 'This indicates if sending of the password reset link was successful.'
  9. def self.authorize(...)
  10. true
  11. end
  12. def ready?(username:)
  13. throttle!(limit: 3, period: 1.minute, by_identifier: username)
  14. end
  15. def resolve(username:)
  16. verify = Service::User::PasswordReset::Send.new(username: username)
  17. begin
  18. verify.execute
  19. rescue Service::User::PasswordReset::Send::EmailError => e
  20. return error_response({ message: e.message })
  21. end
  22. { success: true }
  23. end
  24. end
  25. end