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.

128 lines
3.8 KiB

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