EmailBuilder.coffee 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. _ = require('underscore')
  2. PersonalEmailLayout = require("./Layouts/PersonalEmailLayout")
  3. NotificationEmailLayout = require("./Layouts/NotificationEmailLayout")
  4. BaseWithHeaderEmailLayout = require("./Layouts/BaseWithHeaderEmailLayout")
  5. SingleCTAEmailBody = require("./Bodies/SingleCTAEmailBody")
  6. settings = require("settings-sharelatex")
  7. templates = {}
  8. templates.registered =
  9. subject: _.template "Activate your #{settings.appName} Account"
  10. layout: PersonalEmailLayout
  11. type: "notification"
  12. plainTextTemplate: _.template """
  13. Congratulations, you've just had an account created for you on #{settings.appName} with the email address "<%= to %>".
  14. Click here to set your password and log in: <%= setNewPasswordUrl %>
  15. If you have any questions or problems, please contact #{settings.adminEmail}
  16. """
  17. compiledTemplate: _.template """
  18. <p>Congratulations, you've just had an account created for you on #{settings.appName} with the email address "<%= to %>".</p>
  19. <p><a href="<%= setNewPasswordUrl %>">Click here to set your password and log in.</a></p>
  20. <p>If you have any questions or problems, please contact <a href="mailto:#{settings.adminEmail}">#{settings.adminEmail}</a>.</p>
  21. """
  22. templates.canceledSubscription =
  23. subject: _.template "ShareLaTeX thoughts"
  24. layout: PersonalEmailLayout
  25. type:"lifecycle"
  26. plainTextTemplate: _.template """
  27. Hi <%= first_name %>,
  28. I'm sorry to see you cancelled your ShareLaTeX premium account. Would you mind giving me some advice on what the site is lacking at the moment via this survey?:
  29. https://sharelatex.typeform.com/to/f5lBiZ
  30. Thank you in advance.
  31. Henry
  32. ShareLaTeX Co-founder
  33. """
  34. compiledTemplate: _.template '''
  35. <p>Hi <%= first_name %>,</p>
  36. <p>I'm sorry to see you cancelled your ShareLaTeX premium account. Would you mind giving me some advice on what the site is lacking at the moment via <a href="https://sharelatex.typeform.com/to/f5lBiZ">this survey</a>?</p>
  37. <p>Thank you in advance.</p>
  38. <p>
  39. Henry <br>
  40. ShareLaTeX Co-founder
  41. </p>
  42. '''
  43. templates.passwordResetRequested =
  44. subject: _.template "Password Reset - #{settings.appName}"
  45. layout: BaseWithHeaderEmailLayout
  46. type:"notification"
  47. plainTextTemplate: _.template """
  48. Password Reset
  49. We got a request to reset your #{settings.appName} password.
  50. Click this link to reset your password: <%= setNewPasswordUrl %>
  51. If you ignore this message, your password won't be changed.
  52. If you didn't request a password reset, let us know.
  53. Thank you
  54. #{settings.appName} - <%= siteUrl %>
  55. """
  56. compiledTemplate: (opts) ->
  57. SingleCTAEmailBody({
  58. title: "Password Reset"
  59. greeting: "Hi,"
  60. message: "We got a request to reset your #{settings.appName} password."
  61. secondaryMessage: "If you ignore this message, your password won't be changed.<br>If you didn't request a password reset, let us know."
  62. ctaText: "Reset password"
  63. ctaURL: opts.setNewPasswordUrl
  64. gmailGoToAction: null
  65. })
  66. templates.projectInvite =
  67. subject: _.template "<%= project.name %> - shared by <%= owner.email %>"
  68. layout: BaseWithHeaderEmailLayout
  69. type:"notification"
  70. plainTextTemplate: _.template """
  71. Hi, <%= owner.email %> wants to share '<%= project.name %>' with you.
  72. Follow this link to view the project: <%= inviteUrl %>
  73. Thank you
  74. #{settings.appName} - <%= siteUrl %>
  75. """
  76. compiledTemplate: (opts) ->
  77. SingleCTAEmailBody({
  78. title: "#{ opts.project.name } &ndash; shared by #{ opts.owner.email }"
  79. greeting: "Hi,"
  80. message: "#{ opts.owner.email } wants to share &ldquo;#{ opts.project.name }&rdquo; with you."
  81. secondaryMessage: null
  82. ctaText: "View project"
  83. ctaURL: opts.inviteUrl
  84. gmailGoToAction:
  85. target: opts.inviteUrl
  86. name: "View project"
  87. description: "Join #{ opts.project.name } at ShareLaTeX"
  88. })
  89. templates.completeJoinGroupAccount =
  90. subject: _.template "Verify Email to join <%= group_name %> group"
  91. layout: BaseWithHeaderEmailLayout
  92. type:"notification"
  93. plainTextTemplate: _.template """
  94. Hi, please verify your email to join the <%= group_name %> and get your free premium account
  95. Click this link to verify now: <%= completeJoinUrl %>
  96. Thank You
  97. #{settings.appName} - <%= siteUrl %>
  98. """
  99. compiledTemplate: (opts) ->
  100. SingleCTAEmailBody({
  101. title: "Verify Email to join #{ opts.group_name } group"
  102. greeting: "Hi,"
  103. message: "please verify your email to join the #{ opts.group_name } group and get your free premium account."
  104. secondaryMessage: null
  105. ctaText: "Verify now"
  106. ctaURL: opts.completeJoinUrl
  107. gmailGoToAction: null
  108. })
  109. templates.testEmail =
  110. subject: _.template "A Test Email from ShareLaTeX"
  111. layout: BaseWithHeaderEmailLayout
  112. type:"notification"
  113. plainTextTemplate: _.template """
  114. Hi,
  115. This is a test email sent from ShareLaTeX.
  116. #{settings.appName} - <%= siteUrl %>
  117. """
  118. compiledTemplate: (opts) ->
  119. SingleCTAEmailBody({
  120. title: "A Test Email from ShareLaTeX"
  121. greeting: "Hi,"
  122. message: "This is a test email sent from ShareLaTeX"
  123. secondaryMessage: null
  124. ctaText: "Open ShareLaTeX"
  125. ctaURL: "/"
  126. gmailGoToAction: null
  127. })
  128. module.exports =
  129. templates: templates
  130. buildEmail: (templateName, opts)->
  131. template = templates[templateName]
  132. opts.siteUrl = settings.siteUrl
  133. opts.body = template.compiledTemplate(opts)
  134. if settings.email?.templates?.customFooter?
  135. opts.body += settings.email?.templates?.customFooter
  136. return {
  137. subject : template.subject(opts)
  138. html: template.layout(opts)
  139. text: template?.plainTextTemplate?(opts)
  140. type:template.type
  141. }