send_admin_token.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::Auth::SendAdminToken < Service::Base
  3. include Service::Auth::Concerns::CheckAdminPasswordAuth
  4. attr_reader :login
  5. def initialize(login:)
  6. super()
  7. @login = login
  8. @path = 'desktop/login?token='
  9. end
  10. def execute
  11. admin_password_auth!
  12. result = ::User.admin_password_auth_new_token(login)
  13. raise TokenError if !result || !result[:token]
  14. raise EmailError if !result[:user] || result[:user].email.blank?
  15. result[:url] = "#{Setting.get('http_type')}://#{Setting.get('fqdn')}/#{@path}#{result[:token].token}"
  16. NotificationFactory::Mailer.notification(
  17. template: 'admin_password_auth',
  18. user: result[:user],
  19. objects: result
  20. )
  21. true
  22. end
  23. class TokenError < StandardError
  24. def initialize
  25. super(__('The user token could not be generated.'))
  26. end
  27. end
  28. class EmailError < StandardError
  29. def initialize
  30. super(__('The email could not be sent to the user.'))
  31. end
  32. end
  33. end