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

146 lines
4.4 KiB

  1. # frozen_string_literal: true
  2. class UserMailer < Devise::Mailer
  3. layout 'mailer'
  4. helper :accounts
  5. helper :application
  6. helper :instance
  7. helper :statuses
  8. add_template_helper RoutingHelper
  9. def confirmation_instructions(user, token, **)
  10. @resource = user
  11. @token = token
  12. @instance = Rails.configuration.x.local_domain
  13. return if @resource.disabled?
  14. I18n.with_locale(@resource.locale || I18n.default_locale) do
  15. mail to: @resource.unconfirmed_email.presence || @resource.email,
  16. subject: I18n.t(@resource.pending_reconfirmation? ? 'devise.mailer.reconfirmation_instructions.subject' : 'devise.mailer.confirmation_instructions.subject', instance: @instance),
  17. template_name: @resource.pending_reconfirmation? ? 'reconfirmation_instructions' : 'confirmation_instructions'
  18. end
  19. end
  20. def reset_password_instructions(user, token, **)
  21. @resource = user
  22. @token = token
  23. @instance = Rails.configuration.x.local_domain
  24. return if @resource.disabled?
  25. I18n.with_locale(@resource.locale || I18n.default_locale) do
  26. mail to: @resource.email, subject: I18n.t('devise.mailer.reset_password_instructions.subject')
  27. end
  28. end
  29. def password_change(user, **)
  30. @resource = user
  31. @instance = Rails.configuration.x.local_domain
  32. return if @resource.disabled?
  33. I18n.with_locale(@resource.locale || I18n.default_locale) do
  34. mail to: @resource.email, subject: I18n.t('devise.mailer.password_change.subject')
  35. end
  36. end
  37. def email_changed(user, **)
  38. @resource = user
  39. @instance = Rails.configuration.x.local_domain
  40. return if @resource.disabled?
  41. I18n.with_locale(@resource.locale || I18n.default_locale) do
  42. mail to: @resource.email, subject: I18n.t('devise.mailer.email_changed.subject')
  43. end
  44. end
  45. def two_factor_enabled(user, **)
  46. @resource = user
  47. @instance = Rails.configuration.x.local_domain
  48. return if @resource.disabled?
  49. I18n.with_locale(@resource.locale || I18n.default_locale) do
  50. mail to: @resource.email, subject: I18n.t('devise.mailer.two_factor_enabled.subject')
  51. end
  52. end
  53. def two_factor_disabled(user, **)
  54. @resource = user
  55. @instance = Rails.configuration.x.local_domain
  56. return if @resource.disabled?
  57. I18n.with_locale(@resource.locale || I18n.default_locale) do
  58. mail to: @resource.email, subject: I18n.t('devise.mailer.two_factor_disabled.subject')
  59. end
  60. end
  61. def two_factor_recovery_codes_changed(user, **)
  62. @resource = user
  63. @instance = Rails.configuration.x.local_domain
  64. return if @resource.disabled?
  65. I18n.with_locale(@resource.locale || I18n.default_locale) do
  66. mail to: @resource.email, subject: I18n.t('devise.mailer.two_factor_recovery_codes_changed.subject')
  67. end
  68. end
  69. def welcome(user)
  70. @resource = user
  71. @instance = Rails.configuration.x.local_domain
  72. return if @resource.disabled?
  73. I18n.with_locale(@resource.locale || I18n.default_locale) do
  74. mail to: @resource.email, subject: I18n.t('user_mailer.welcome.subject')
  75. end
  76. end
  77. def backup_ready(user, backup)
  78. @resource = user
  79. @instance = Rails.configuration.x.local_domain
  80. @backup = backup
  81. return if @resource.disabled?
  82. I18n.with_locale(@resource.locale || I18n.default_locale) do
  83. mail to: @resource.email, subject: I18n.t('user_mailer.backup_ready.subject')
  84. end
  85. end
  86. def warning(user, warning, status_ids = nil)
  87. @resource = user
  88. @warning = warning
  89. @instance = Rails.configuration.x.local_domain
  90. @statuses = Status.where(id: status_ids).includes(:account) if status_ids.is_a?(Array)
  91. I18n.with_locale(@resource.locale || I18n.default_locale) do
  92. mail to: @resource.email,
  93. subject: I18n.t("user_mailer.warning.subject.#{@warning.action}", acct: "@#{user.account.local_username_and_domain}"),
  94. reply_to: Setting.site_contact_email
  95. end
  96. end
  97. def sign_in_token(user, remote_ip, user_agent, timestamp)
  98. @resource = user
  99. @instance = Rails.configuration.x.local_domain
  100. @remote_ip = remote_ip
  101. @user_agent = user_agent
  102. @detection = Browser.new(user_agent)
  103. @timestamp = timestamp.to_time.utc
  104. return if @resource.disabled?
  105. I18n.with_locale(@resource.locale || I18n.default_locale) do
  106. mail to: @resource.email,
  107. subject: I18n.t('user_mailer.sign_in_token.subject'),
  108. reply_to: Setting.site_contact_email
  109. end
  110. end
  111. end