Commit 29e4df2f authored by Jarrod's avatar Jarrod 💬

Update resend-verification.js

parent 7edd0149
Pipeline #6708 passed with stage
in 54 seconds
module.exports = {
friendlyName: 'Re-send verification email',
description: '',
inputs: {
},
exits: {
},
fn: async function (inputs, exits) {
const uuid = require('uuid/v4')
const crypto = require('crypto')
let user = this.req.me
if (!user) { return this.res.unauthorized() }
let emailHash = crypto
.createHash('md5')
.update(user.emailChangeCandidate ? user.emailChangeCandidate : user.emailAddress, 'utf8')
.digest('hex')
if (!user.emailVerificationToken) {
user = await User.updateOne({ id: user.id })
.set({
emailVerificationToken: uuid()
// TODO:: emailVerificationTokenExpiresAt: new Date(now - 2-24hrs?)
})
}
// Send the email (async!)
try {
await sails.helpers.ahoy.email.send('email-verification', user.emailChangeCandidate ? user.emailChangeCandidate : user.email, {
subject: `Verify your email for ${sails.config.custom.site.name}`,
user: user,
email: emailHash,
token: user.emailVerificationToken
})
} catch (err) {
sails.log.error(`Unable to resend verification email`, err)
return res.serverError('Unable to send verification email')
}
return exits.success({ status: 'ok' })
}
}
module.exports = {
friendlyName: 'Re-send verification email',
description: '',
inputs: {
},
exits: {
},
fn: async function (inputs, exits) {
const uuid = require('uuid/v4')
const crypto = require('crypto')
let user = this.req.me
if (!user) { return this.res.unauthorized() }
let emailHash = crypto
.createHash('md5')
.update(user.emailChangeCandidate ? user.emailChangeCandidate : user.emailAddress, 'utf8')
.digest('hex')
if (!user.emailVerificationToken) {
user = await User.updateOne({ id: user.id })
.set({
emailVerificationToken: uuid()
// TODO:: emailVerificationTokenExpiresAt: new Date(now - 2-24hrs?)
})
}
// Send the email (async!)
try {
await sails.helpers.ahoy.email.send('email-verification', user.emailChangeCandidate ? user.emailChangeCandidate : user.emailAddress, {
subject: `Verify your email for ${sails.config.custom.site.name}`,
user: user,
email: emailHash,
token: user.emailVerificationToken
})
} catch (err) {
sails.log.error(`Unable to resend verification email`, err)
return res.serverError('Unable to send verification email')
}
return exits.success({ status: 'ok' })
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment