discourse/app/mailers/invite_mailer.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
2.4 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
2013-02-05 14:16:51 -05:00
class InviteMailer < ActionMailer::Base
include Email::BuildEmailHelper
2013-02-07 10:45:24 -05:00
layout "email_template"
def send_invite(invite, invite_to_topic: false)
2013-02-05 14:16:51 -05:00
# Find the first topic they were invited to
first_topic = invite.topics.order(:created_at).first
2014-07-10 01:27:40 -04:00
# get invitee name (based on site setting)
inviter_name = invite.invited_by.username
if SiteSetting.enable_names && invite.invited_by.name.present?
inviter_name = "#{invite.invited_by.name} (#{invite.invited_by.username})"
2014-07-10 01:27:40 -04:00
end
sanitized_message =
(
if invite.custom_message.present?
ActionView::Base.full_sanitizer.sanitize(invite.custom_message.gsub(/\n+/, " ").strip)
else
nil
end
)
2013-02-05 14:16:51 -05:00
# If they were invited to a topic
if invite_to_topic && first_topic.present?
# get topic excerpt
topic_excerpt = ""
topic_excerpt = first_topic.excerpt.tr("\n", " ") if first_topic.excerpt
topic_title = first_topic.try(:title)
if SiteSetting.private_email?
2017-04-27 11:45:49 -04:00
topic_title = I18n.t("system_messages.private_topic_title", id: first_topic.id)
topic_excerpt = ""
end
build_email(
invite.email,
template: sanitized_message ? "custom_invite_mailer" : "invite_mailer",
inviter_name: inviter_name,
site_domain_name: Discourse.current_hostname,
invite_link: invite.link(with_email_token: true),
topic_title: topic_title,
topic_excerpt: topic_excerpt,
2014-06-14 18:49:19 -04:00
site_description: SiteSetting.site_description,
2016-06-08 08:34:25 -04:00
site_title: SiteSetting.title,
user_custom_message: sanitized_message,
)
else
build_email(
invite.email,
template: sanitized_message ? "custom_invite_forum_mailer" : "invite_forum_mailer",
inviter_name: inviter_name,
2014-07-10 01:27:40 -04:00
site_domain_name: Discourse.current_hostname,
invite_link: invite.link(with_email_token: true),
2014-06-14 18:49:19 -04:00
site_description: SiteSetting.site_description,
2016-06-08 08:34:25 -04:00
site_title: SiteSetting.title,
user_custom_message: sanitized_message,
)
end
2013-02-05 14:16:51 -05:00
end
def send_password_instructions(user)
if user.present?
email_token =
user.email_tokens.create!(email: user.email, scope: EmailToken.scopes[:password_reset])
build_email(
user.email,
template: "invite_password_instructions",
email_token: email_token.token,
)
end
end
2013-02-05 14:16:51 -05:00
end