Newer
Older
const config = require('config')
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',
})
const email = new Email({
toUser: {
email: user.email,
},
fromEmail: `${journalName} <${staffEmail}>`,
content: {
subject: 'Forgot Password',
ctaLink: services.createUrl(baseUrl, forgotPath, {
email: user.email,
}),
ctaText: 'RESET PASSWORD',
paragraph,
unsubscribeLink: services.createUrl(baseUrl, unsubscribeSlug, {
id: user.id,
token: user.accessTokens.unsubscribe,
}),
},
})