update.rb 969 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::User::PasswordReset::Update < Service::Base
  3. attr_reader :token, :password
  4. def initialize(token:, password:)
  5. super()
  6. @token = token
  7. @password = password
  8. end
  9. def execute
  10. Service::CheckFeatureEnabled.new(name: 'user_lost_password').execute
  11. PasswordPolicy.new(password).valid!
  12. user = ::User.password_reset_via_token(token, password)
  13. raise InvalidTokenError if !user
  14. raise EmailError if user.email.blank?
  15. NotificationFactory::Mailer.notification(
  16. template: 'password_change',
  17. user: user,
  18. objects: {
  19. user: user,
  20. }
  21. )
  22. user
  23. end
  24. class InvalidTokenError < StandardError
  25. def initialize
  26. super(__('The provided token is invalid.'))
  27. end
  28. end
  29. class EmailError < StandardError
  30. def initialize
  31. super(__('The email could not be sent to the user.'))
  32. end
  33. end
  34. end