Newer
Older
const config = require('config')
const unsubscribeSlug = config.get('unsubscribe.url')
const resetPath = config.get('invite-reset-password.url')
const confirmSignUp = config.get('confirm-signup.url')
const { Email, User, services } = require('pubsweet-component-helper-service')
const { getEmailCopy } = require('./emailCopy')
module.exports = {
async sendNotifications({ user, baseUrl, role, UserModel }) {
const userHelper = new User({ UserModel })

Sebastian Mihalache
committed
const eicName = await userHelper.getEiCName()
const email = new Email({
type: 'user',
toUser: {
email: user.email,
name: `${user.firstName} ${user.lastName}`,
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
},
content: {
ctaLink: services.createUrl(baseUrl, resetPath, {
email: user.email,
token: user.passwordResetToken,
firstName: user.firstName,
lastName: user.lastName,
affiliation: user.affiliation,
title: user.title,
}),
ctaText: 'CONFIRM ACCOUNT',
signatureName: eicName,
unsubscribeLink: services.createUrl(baseUrl, unsubscribeSlug, {
id: user.id,
}),
},
})
if (role) {
sendNewUserEmail({ email, role })
} else {
sendSignupEmail({ email, baseUrl, user })
}
},
}
const sendNewUserEmail = ({ email, role }) => {
email.content.subject = 'Confirm Your Account'
const { html, text } = email.getBody({
body: getEmailCopy({
emailType: 'user-added-by-admin',
role,
}),
})
email.sendEmail({ html, text })
}
const sendSignupEmail = ({ email, baseUrl, user }) => {
email.content.subject = 'Confirm Your Email Address'
email.content.ctaLink = services.createUrl(baseUrl, confirmSignUp, {
userId: user.id,
confirmationToken: user.confirmationToken,
})
email.content.ctaText = 'CONFIRM'
const { html, text } = email.getBody({
body: getEmailCopy({
emailType: 'user-signup',
}),
})
email.sendEmail({ html, text })
}