Skip to content
Snippets Groups Projects
notifications.js 1.16 KiB
Newer Older
const Email = require('@pubsweet/component-email-templating')

const { services } = require('pubsweet-component-helper-service')

const { getEmailCopy } = require('./emailCopy')

const forgotPath = config.get('forgot-password.url')
const { name: journalName, staffEmail } = config.get('journal')
const unsubscribeSlug = config.get('unsubscribe.url')

module.exports = {
  async sendForgotPasswordEmail({ user, baseUrl }) {
    const { paragraph, ...bodyProps } = getEmailCopy({
      emailType: 'user-forgot-password',
    })

      type: 'system',
      toUser: {
        email: user.email,
      },
      fromEmail: `${journalName} <${staffEmail}>`,
        subject: 'Forgot Password',
        ctaLink: services.createUrl(baseUrl, forgotPath, {
          email: user.email,
          token: user.accessTokens.passwordReset,
        paragraph,
        unsubscribeLink: services.createUrl(baseUrl, unsubscribeSlug, {
          id: user.id,
          token: user.accessTokens.unsubscribe,
        }),