update.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # frozen_string_literal: true
  3. module Gql::Mutations
  4. class User::PasswordReset::Update < BaseMutation
  5. description 'Update user password via reset token.'
  6. argument :token, String, required: true, description: 'Verification token'
  7. argument :password, String, required: true, description: 'The user password'
  8. field :success, Boolean, description: 'This indicates if the password update was successful.'
  9. def self.authorize(...)
  10. true
  11. end
  12. def resolve(token:, password:)
  13. update = Service::User::PasswordReset::Update.new(token: token, password: password)
  14. begin
  15. update.execute
  16. rescue Service::User::PasswordReset::Update::InvalidTokenError, Service::User::PasswordReset::Update::EmailError => e
  17. return error_response({ message: e.message })
  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