signup.rb 880 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class User::Signup < BaseMutation
  4. include Gql::Concerns::HandlesThrottling
  5. description 'Sign-up / register user.'
  6. argument :input, Gql::Types::Input::User::SignupInputType, description: 'The user data'
  7. field :success, Boolean, description: 'This indicates if creating the user and sending the token was successful.'
  8. def self.authorize(...)
  9. true
  10. end
  11. def ready?(input:)
  12. throttle!(limit: 3, period: 1.minute, by_identifier: input[:email])
  13. end
  14. def resolve(input:)
  15. signup = Service::User::Signup.new(user_data: input.to_h)
  16. begin
  17. signup.execute
  18. rescue PasswordPolicy::Error => e
  19. return error_response({ message: e.message, field: 'password' })
  20. end
  21. { success: true }
  22. end
  23. end
  24. end