password_check.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class User::Current::PasswordCheck < BaseMutation
  4. include Gql::Concerns::HandlesThrottling
  5. description 'Check your password'
  6. argument :password, String, required: true, description: 'Password to check'
  7. field :success, Boolean, description: 'This indicates if given password matches current user password'
  8. field :token, String, description: 'One-time token which should be included in a subsequent request (where applicable)'
  9. def self.authorize(_obj, ctx)
  10. ctx.current_user.permissions?('user_preferences.password')
  11. end
  12. def ready?(...)
  13. throttle!(limit: 10, period: 1.minute, by_identifier: context.current_user.login)
  14. end
  15. def resolve(password:)
  16. password_check = Service::User::PasswordCheck
  17. .new(user: context.current_user, password:)
  18. .execute
  19. if !password_check[:success]
  20. return error_response({ field: :password, message: __('The provided password is incorrect.') })
  21. end
  22. password_check
  23. end
  24. end
  25. end