Skip to content

Commit

Permalink
nicer emails and add user id to email links (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Schroter authored and KristerV committed Oct 4, 2017
1 parent e11bafd commit b037f48
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .env
Expand Up @@ -6,4 +6,4 @@ DB_USER=postgres
DB_PASSWORD=postgres
JWT_SECRET=development
FRONTEND_URL=http://localhost:5000
SUPPORT_EMAIL=Support <support@heliumlabs.org>
SUPPORT_EMAIL=Helium Labs [DEV] <support@heliumlabs.org>
12 changes: 8 additions & 4 deletions mailer/index.js
Expand Up @@ -2,22 +2,26 @@
// return type of getClient need to be mocked in setupTests.js
const getClient = require('./getClient')

module.exports.sendEmailConfirmation = async (to, token) => {
module.exports.sendEmailConfirmation = async (to, userId, token) => {
const client = getClient()
const url = `${process.env.FRONTEND_URL}/confirmEmail?userId=${userId}&token=${token}`
return client.send({
to,
from: process.env.SUPPORT_EMAIL,
subject: 'Email Confirmation',
text: `${process.env.FRONTEND_URL}/confirmEmail?token=${token}`
text: `Confirm your email: ${url}`,
html: `<a href=${url}>Confirm your email</a>`
})
}

module.exports.sendPasswordReset = async (to, token) => {
module.exports.sendPasswordReset = async (to, userId, token) => {
const client = getClient()
const url = `${process.env.FRONTEND_URL}/changePassword?userId=${userId}&token=${token}`
return client.send({
to,
from: process.env.SUPPORT_EMAIL,
subject: 'Reset Password',
text: `${process.env.FRONTEND_URL}/changePassword?token=${token}`
text: `Reset your password: ${url}`,
html: `<a href=${url}>Reset your password</a>`
})
}
2 changes: 1 addition & 1 deletion v0/routes/login/sendPasswordResetEmail.js
Expand Up @@ -16,7 +16,7 @@ module.exports = async (req, res) => {
{ subject: encodeId(user.id), expiresIn: '5m' }
)

await mailer.sendPasswordReset(user.email, token)
await mailer.sendPasswordReset(user.email, encodeId(user.id), token)

res.json(true)
}
2 changes: 1 addition & 1 deletion v0/routes/users/createUser.js
Expand Up @@ -23,7 +23,7 @@ module.exports = async (req, res) => {
{ subject: encodeId(user.id), expiresIn: '5m' }
)

await mailer.sendEmailConfirmation(user.email, token)
await mailer.sendEmailConfirmation(user.email, encodeId(user.id), token)
}

res.json(User.toJSON(user))
Expand Down
2 changes: 1 addition & 1 deletion v0/routes/users/updateUser.js
Expand Up @@ -26,7 +26,7 @@ module.exports = async (req, res) => {
{ subject: encodeId(user.id), expiresIn: '5m' }
)

await mailer.sendEmailConfirmation(user.email, token)
await mailer.sendEmailConfirmation(user.email, encodeId(user.id), token)
}

const updatedUser = await User.update(user.id, {
Expand Down

0 comments on commit b037f48

Please sign in to comment.