闭社主体 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.

93 lines
2.8 KiB

  1. # frozen_string_literal: true
  2. class UserMailer < Devise::Mailer
  3. layout 'mailer'
  4. helper :application
  5. helper :instance
  6. add_template_helper RoutingHelper
  7. def confirmation_instructions(user, token, **)
  8. @resource = user
  9. @token = token
  10. @instance = Rails.configuration.x.local_domain
  11. return if @resource.disabled?
  12. I18n.with_locale(@resource.locale || I18n.default_locale) do
  13. mail to: @resource.unconfirmed_email.presence || @resource.email,
  14. subject: I18n.t(@resource.pending_reconfirmation? ? 'devise.mailer.reconfirmation_instructions.subject' : 'devise.mailer.confirmation_instructions.subject', instance: @instance),
  15. template_name: @resource.pending_reconfirmation? ? 'reconfirmation_instructions' : 'confirmation_instructions'
  16. end
  17. end
  18. def reset_password_instructions(user, token, **)
  19. @resource = user
  20. @token = token
  21. @instance = Rails.configuration.x.local_domain
  22. return if @resource.disabled?
  23. I18n.with_locale(@resource.locale || I18n.default_locale) do
  24. mail to: @resource.email, subject: I18n.t('devise.mailer.reset_password_instructions.subject')
  25. end
  26. end
  27. def password_change(user, **)
  28. @resource = user
  29. @instance = Rails.configuration.x.local_domain
  30. return if @resource.disabled?
  31. I18n.with_locale(@resource.locale || I18n.default_locale) do
  32. mail to: @resource.email, subject: I18n.t('devise.mailer.password_change.subject')
  33. end
  34. end
  35. def email_changed(user, **)
  36. @resource = user
  37. @instance = Rails.configuration.x.local_domain
  38. return if @resource.disabled?
  39. I18n.with_locale(@resource.locale || I18n.default_locale) do
  40. mail to: @resource.email, subject: I18n.t('devise.mailer.email_changed.subject')
  41. end
  42. end
  43. def welcome(user)
  44. @resource = user
  45. @instance = Rails.configuration.x.local_domain
  46. return if @resource.disabled?
  47. I18n.with_locale(@resource.locale || I18n.default_locale) do
  48. mail to: @resource.email, subject: I18n.t('user_mailer.welcome.subject')
  49. end
  50. end
  51. def backup_ready(user, backup)
  52. @resource = user
  53. @instance = Rails.configuration.x.local_domain
  54. @backup = backup
  55. return if @resource.disabled?
  56. I18n.with_locale(@resource.locale || I18n.default_locale) do
  57. mail to: @resource.email, subject: I18n.t('user_mailer.backup_ready.subject')
  58. end
  59. end
  60. def warning(user, warning)
  61. @resource = user
  62. @warning = warning
  63. @instance = Rails.configuration.x.local_domain
  64. I18n.with_locale(@resource.locale || I18n.default_locale) do
  65. mail to: @resource.email,
  66. subject: I18n.t("user_mailer.warning.subject.#{@warning.action}", acct: "@#{user.account.local_username_and_domain}"),
  67. reply_to: Setting.site_contact_email
  68. end
  69. end
  70. end