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.

81 lines
2.4 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.blank? ? @resource.email : @resource.unconfirmed_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. end