闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

  1. # frozen_string_literal: true
  2. class UserMailer < Devise::Mailer
  3. layout 'mailer'
  4. helper :instance
  5. add_template_helper RoutingHelper
  6. def confirmation_instructions(user, token, **)
  7. @resource = user
  8. @token = token
  9. @instance = Rails.configuration.x.local_domain
  10. return if @resource.disabled?
  11. I18n.with_locale(@resource.locale || I18n.default_locale) do
  12. mail to: @resource.unconfirmed_email.blank? ? @resource.email : @resource.unconfirmed_email,
  13. subject: I18n.t(@resource.pending_reconfirmation? ? 'devise.mailer.reconfirmation_instructions.subject' : 'devise.mailer.confirmation_instructions.subject', instance: @instance),
  14. template_name: @resource.pending_reconfirmation? ? 'reconfirmation_instructions' : 'confirmation_instructions'
  15. end
  16. end
  17. def reset_password_instructions(user, token, **)
  18. @resource = user
  19. @token = token
  20. @instance = Rails.configuration.x.local_domain
  21. return if @resource.disabled?
  22. I18n.with_locale(@resource.locale || I18n.default_locale) do
  23. mail to: @resource.email, subject: I18n.t('devise.mailer.reset_password_instructions.subject')
  24. end
  25. end
  26. def password_change(user, **)
  27. @resource = user
  28. @instance = Rails.configuration.x.local_domain
  29. return if @resource.disabled?
  30. I18n.with_locale(@resource.locale || I18n.default_locale) do
  31. mail to: @resource.email, subject: I18n.t('devise.mailer.password_change.subject')
  32. end
  33. end
  34. def email_changed(user, **)
  35. @resource = user
  36. @instance = Rails.configuration.x.local_domain
  37. return if @resource.disabled?
  38. I18n.with_locale(@resource.locale || I18n.default_locale) do
  39. mail to: @resource.email, subject: I18n.t('devise.mailer.email_changed.subject')
  40. end
  41. end
  42. def welcome(user)
  43. @resource = user
  44. @instance = Rails.configuration.x.local_domain
  45. return if @resource.disabled?
  46. I18n.with_locale(@resource.locale || I18n.default_locale) do
  47. mail to: @resource.email, subject: I18n.t('user_mailer.welcome.subject')
  48. end
  49. end
  50. end