2013-06-10 16:46:08 -04:00
|
|
|
require_dependency 'email/message_builder'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
class InviteMailer < ActionMailer::Base
|
2013-06-10 16:46:08 -04:00
|
|
|
include Email::BuildEmailHelper
|
2013-02-07 10:45:24 -05:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
def send_invite(invite)
|
|
|
|
# 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)
|
|
|
|
invitee_name = invite.invited_by.username
|
|
|
|
if (SiteSetting.enable_names)
|
|
|
|
invitee_name = "#{invite.invited_by.name} (#{invite.invited_by.username})"
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
# If they were invited to a topic
|
2013-11-06 12:56:26 -05:00
|
|
|
if first_topic.present?
|
2014-07-08 13:03:11 -04:00
|
|
|
# get topic excerpt
|
|
|
|
topic_excerpt = ""
|
|
|
|
if first_topic.excerpt
|
|
|
|
topic_excerpt = first_topic.excerpt.gsub("\n", " ")
|
|
|
|
end
|
|
|
|
|
2013-11-06 12:56:26 -05:00
|
|
|
build_email(invite.email,
|
|
|
|
template: 'invite_mailer',
|
2014-07-08 13:03:11 -04:00
|
|
|
invitee_name: invitee_name,
|
2014-07-10 00:33:09 -04:00
|
|
|
site_domain_name: Discourse.current_hostname,
|
2013-11-06 12:56:26 -05:00
|
|
|
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
|
2014-06-14 18:49:19 -04:00
|
|
|
topic_title: first_topic.try(:title),
|
2014-07-08 13:03:11 -04:00
|
|
|
topic_excerpt: topic_excerpt,
|
2014-06-14 18:49:19 -04:00
|
|
|
site_description: SiteSetting.site_description,
|
|
|
|
site_title: SiteSetting.title)
|
2013-11-06 12:56:26 -05:00
|
|
|
else
|
|
|
|
build_email(invite.email,
|
|
|
|
template: 'invite_forum_mailer',
|
2014-07-10 01:27:40 -04:00
|
|
|
invitee_name: invitee_name,
|
|
|
|
site_domain_name: Discourse.current_hostname,
|
2014-06-14 18:49:19 -04:00
|
|
|
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
|
|
|
|
site_description: SiteSetting.site_description,
|
|
|
|
site_title: SiteSetting.title)
|
2013-11-06 12:56:26 -05:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2014-10-10 11:47:52 -04:00
|
|
|
def send_password_instructions(user)
|
|
|
|
if user.present?
|
|
|
|
email_token = user.email_tokens.create(email: user.email)
|
|
|
|
build_email(user.email,
|
|
|
|
template: 'invite_password_instructions',
|
|
|
|
email_token: email_token.token)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|