EmailBuilder.coffee 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. _ = require('underscore')
  2. settings = require("settings-sharelatex")
  3. marked = require('marked')
  4. StringHelper = require "../Helpers/StringHelper"
  5. PersonalEmailLayout = require("./Layouts/PersonalEmailLayout")
  6. NotificationEmailLayout = require("./Layouts/NotificationEmailLayout")
  7. BaseWithHeaderEmailLayout = require("./Layouts/" + settings.brandPrefix + "BaseWithHeaderEmailLayout")
  8. SpamSafe = require("./SpamSafe")
  9. SingleCTAEmailBody = require("./Bodies/" + settings.brandPrefix + "SingleCTAEmailBody")
  10. CTAEmailTemplate = (content) ->
  11. content.greeting ?= () -> 'Hi,'
  12. content.secondaryMessage ?= () -> ""
  13. return {
  14. subject: (opts) -> content.subject(opts),
  15. layout: BaseWithHeaderEmailLayout,
  16. plainTextTemplate: (opts) -> """
  17. #{content.greeting(opts)}
  18. #{content.message(opts).trim()}
  19. #{content.ctaText(opts)}: #{content.ctaURL(opts)}
  20. #{content.secondaryMessage?(opts).trim() or ""}
  21. Regards,
  22. The #{settings.appName} Team - #{settings.siteUrl}
  23. """
  24. compiledTemplate: (opts) ->
  25. SingleCTAEmailBody({
  26. title: content.title?(opts)
  27. greeting: content.greeting(opts)
  28. message: marked(content.message(opts).trim())
  29. secondaryMessage: marked(content.secondaryMessage(opts).trim())
  30. ctaText: content.ctaText(opts)
  31. ctaURL: content.ctaURL(opts)
  32. gmailGoToAction: content.gmailGoToAction?(opts)
  33. StringHelper: StringHelper
  34. })
  35. }
  36. templates = {}
  37. templates.accountMergeToOverleafAddress = CTAEmailTemplate({
  38. subject: () -> "Confirm Account Merge - #{settings.appName}"
  39. title: () -> "Confirm Account Merge"
  40. message: () ->
  41. """
  42. To merge your ShareLaTeX and Overleaf accounts, click the button below.
  43. If you think you have received this message in error,
  44. please contact us at https://www.overleaf.com/contact
  45. """
  46. ctaText: () -> "Confirm Account Merge"
  47. ctaURL: (opts) -> opts.tokenLinkUrl
  48. })
  49. templates.accountMergeToSharelatexAddress = templates.accountMergeToOverleafAddress
  50. templates.registered = CTAEmailTemplate({
  51. subject: () -> "Activate your #{settings.appName} Account"
  52. message: (opts) -> """
  53. Congratulations, you've just had an account created for you on #{settings.appName} with the email address '#{_.escape(opts.to)}'.
  54. Click here to set your password and log in:
  55. """
  56. secondaryMessage: () -> "If you have any questions or problems, please contact #{settings.adminEmail}"
  57. ctaText: () -> "Set password"
  58. ctaURL: (opts) -> opts.setNewPasswordUrl
  59. })
  60. templates.canceledSubscription = CTAEmailTemplate({
  61. subject: () -> "#{settings.appName} thoughts"
  62. message: () -> """
  63. I'm sorry to see you cancelled your #{settings.appName} premium account. Would you mind giving us some feedback on what the site is lacking at the moment via this quick survey?
  64. """
  65. secondaryMessage: () -> "Thank you in advance!"
  66. ctaText: () -> "Leave Feedback"
  67. ctaURL: (opts) -> "https://docs.google.com/forms/d/e/1FAIpQLScqU6Je1r4Afz6ul6oY0RAfN7RabdWv_oL1u7Rj1YBmXS4fiQ/viewform?usp=sf_link"
  68. })
  69. templates.reactivatedSubscription = CTAEmailTemplate({
  70. subject: () -> "Subscription Reactivated - #{settings.appName}"
  71. message: (opts) -> """
  72. Your subscription was reactivated successfully.
  73. """
  74. ctaText: () -> "View Subscription Dashboard"
  75. ctaURL: (opts) -> "#{settings.siteUrl}/user/subscription"
  76. })
  77. templates.passwordResetRequested = CTAEmailTemplate({
  78. subject: () -> "Password Reset - #{settings.appName}"
  79. title: () -> "Password Reset"
  80. message: () -> "We got a request to reset your #{settings.appName} password."
  81. secondaryMessage: () -> """
  82. If you ignore this message, your password won't be changed.
  83. If you didn't request a password reset, let us know.
  84. """
  85. ctaText: () -> "Reset password"
  86. ctaURL: (opts) -> opts.setNewPasswordUrl
  87. })
  88. templates.confirmEmail = CTAEmailTemplate({
  89. subject: () -> "Confirm Email - #{settings.appName}"
  90. title: () -> "Confirm Email"
  91. message: () -> "Please confirm your email on #{settings.appName}."
  92. ctaText: () -> "Confirm Email"
  93. ctaURL: (opts) -> opts.confirmEmailUrl
  94. })
  95. templates.projectInvite = CTAEmailTemplate({
  96. subject: (opts) -> "#{ _.escape(SpamSafe.safeProjectName(opts.project.name, "New Project")) } - shared by #{ _.escape(SpamSafe.safeEmail(opts.owner.email, "a collaborator")) }"
  97. title: (opts) -> "#{ _.escape(SpamSafe.safeProjectName(opts.project.name, "New Project")) } - shared by #{ _.escape(SpamSafe.safeEmail(opts.owner.email, "a collaborator")) }"
  98. message: (opts) -> "#{ _.escape(SpamSafe.safeEmail(opts.owner.email, "a collaborator")) } wants to share #{ _.escape(SpamSafe.safeProjectName(opts.project.name, "a new project")) } with you."
  99. ctaText: () -> "View project"
  100. ctaURL: (opts) -> opts.inviteUrl
  101. gmailGoToAction: (opts) ->
  102. target: opts.inviteUrl
  103. name: "View project"
  104. description: "Join #{ _.escape(SpamSafe.safeProjectName(opts.project.name, "project")) } at #{ settings.appName }"
  105. })
  106. templates.verifyEmailToJoinTeam = CTAEmailTemplate({
  107. subject: (opts) -> "#{ _.escape(SpamSafe.safeUserName(opts.inviterName, "A collaborator")) } has invited you to join a team on #{ settings.appName }"
  108. title: (opts) -> "#{ _.escape(SpamSafe.safeUserName(opts.inviterName, "A collaborator")) } has invited you to join a team on #{ settings.appName }"
  109. message: (opts) -> "Please click the button below to join the team and enjoy the benefits of an upgraded #{ settings.appName } account."
  110. ctaText: (opts) -> "Join now"
  111. ctaURL: (opts) -> opts.acceptInviteUrl
  112. })
  113. templates.dropboxUnlinkedDuplicate = CTAEmailTemplate({
  114. subject: () -> "Your Dropbox Account has been Unlinked - #{settings.appName}"
  115. message: (opts) -> """
  116. Our automated systems have detected that your Dropbox account was linked to more than one Overleaf accounts. This should not have been allowed and might be causing issues with the Dropbox sync feature.
  117. We have now unlinked all your Dropbox and Overleaf Accounts. To ensure your project will keep syncing you can link your Dropbox account to the Overleaf account of your choice now.
  118. """
  119. ctaText: () -> "Link Dropbox Account"
  120. ctaURL: (opts) -> "#{settings.siteUrl}/user/settings"
  121. })
  122. templates.testEmail = CTAEmailTemplate({
  123. subject: () -> "A Test Email from #{settings.appName}"
  124. title: () -> "A Test Email from #{settings.appName}"
  125. greeting: () -> "Hi,"
  126. message: () -> "This is a test Email from #{settings.appName}"
  127. ctaText: () -> "Open #{settings.appName}"
  128. ctaURL: () -> settings.siteUrl
  129. })
  130. templates.projectsTransferredFromSharelatex = CTAEmailTemplate({
  131. subject: () -> "ShareLaTeX projects transferred to your Overleaf account"
  132. title: () -> "ShareLaTeX projects transferred to your Overleaf account"
  133. message: (opts) -> """
  134. We are writing with important information about your Overleaf and ShareLaTeX accounts.
  135. As part of our ongoing work to [integrate Overleaf and ShareLaTeX](https://www.overleaf.com/blog/518-exciting-news-sharelatex-is-joining-overleaf),
  136. we found a ShareLaTeX account with the email address #{opts.to} that matches your Overleaf account.
  137. We have now transferred the projects from this ShareLaTeX account into your Overleaf account, so you may notice some new
  138. projects on your Overleaf projects page.
  139. When you next log in, you may be prompted to reconfirm your email address in order to regain access to your account.
  140. If you have any questions, please contact our support team by reply.
  141. """
  142. ctaText: () -> "Log in to #{ settings.appName }"
  143. ctaURL: () -> settings.siteUrl + "/login"
  144. })
  145. templates.emailAddressPoachedEmail = CTAEmailTemplate({
  146. subject: () -> "One of your email addresses has been moved to another #{ settings.appName } account"
  147. title: () -> "One of your email addresses has been moved to another #{ settings.appName } account"
  148. message: (opts) ->
  149. message = """
  150. We are writing with important information about your Overleaf account.
  151. You added the email address #{opts.poached} to your #{opts.to} Overleaf account as a secondary (or affiliation)
  152. email address, but we have had to remove it.
  153. This is because your #{opts.poached} email address was also in use as the primary email address for an older Overleaf
  154. account from before our [integration with ShareLaTeX to create Overleaf v2](https://www.overleaf.com/blog/518-exciting-news-sharelatex-is-joining-overleaf).
  155. ### What do I need to do?
  156. You now have two Overleaf accounts, one under #{opts.poached} and one under #{opts.to}.
  157. You may wish to log in to Overleaf as #{opts.poached} to check whether you have projects there that you would like to
  158. keep. If you are not sure of the password, you can send yourself a password reset email to #{opts.poached}, via
  159. https://www.overleaf.com/user/password/reset
  160. Once you have downloaded your projects, you may wish to delete your
  161. #{opts.poached} Overleaf account, which you can do from your account settings. You will then be able to add
  162. #{opts.poached} as a secondary email address on your #{opts.to} account again.
  163. """
  164. if opts.proFeatures
  165. message += """
  166. Because your #{opts.poached} email address was an institutional affiliation through which you had Pro features. Your Pro
  167. features have been transferred to your #{opts.poached} account. If you would like to transfer them back to your
  168. #{opts.to} account, you will need to delete the #{opts.poached} account and re-add it as a secondary email address,
  169. as described above.
  170. """
  171. message += """
  172. If you have any questions, you can contact our support team by reply.
  173. """
  174. return message
  175. ctaText: () -> "Log in to #{ settings.appName }"
  176. ctaURL: () -> settings.siteUrl + "/login"
  177. })
  178. module.exports =
  179. templates: templates
  180. CTAEmailTemplate: CTAEmailTemplate
  181. buildEmail: (templateName, opts)->
  182. template = templates[templateName]
  183. opts.siteUrl = settings.siteUrl
  184. opts.body = template.compiledTemplate(opts)
  185. if settings.email?.templates?.customFooter?
  186. opts.body += settings.email?.templates?.customFooter
  187. return {
  188. subject : template.subject(opts)
  189. html: template.layout(opts)
  190. text: template?.plainTextTemplate?(opts)
  191. }