Just generate a new token on resending confirmation email

This commit is contained in:
James Allen
2018-07-13 10:42:31 +01:00
parent d7e0b8c369
commit 476f4e55c3
4 changed files with 6 additions and 31 deletions
@@ -27,16 +27,6 @@ module.exports =
return callback(error) if error?
callback null, token
findValidTokenFromData: (use, data, callback = (error, token) ->) ->
db.tokens.findOne {
use: use,
data: data,
expiresAt: { $gt: new Date() },
usedAt: { $exists: false }
}, (error, token) ->
return callback(error) if error?
return callback null, token?.token
getValueFromTokenAndExpire: (use, token, callback = (error, data) ->)->
logger.log token_start: token.slice(0,8), "getting data from #{use} token"
now = new Date()
@@ -23,17 +23,6 @@ module.exports = UserEmailsConfirmationHandler =
confirmEmailUrl: "#{settings.siteUrl}/user/emails/confirm?token=#{token}"
EmailHandler.sendEmail emailTemplate, emailOptions, callback
resendConfirmationEmail: (user_id, email, callback = (error) ->) ->
OneTimeTokenHandler.findValidTokenFromData 'email_confirmation', { user_id, email }, (error, token) ->
return callback(error) if error?
if !token?
UserEmailsConfirmationHandler.sendConfirmationEmail user_id, email, callback
else
emailOptions =
to: email
confirmEmailUrl: "#{settings.siteUrl}/user/emails/confirm?token=#{token}"
EmailHandler.sendEmail 'confirmEmail', emailOptions, callback
confirmEmailFromToken: (token, callback = (error) ->) ->
logger.log {token_start: token.slice(0,8)}, 'confirming email from token'
OneTimeTokenHandler.getValueFromTokenAndExpire 'email_confirmation', token, (error, data) ->
@@ -71,7 +71,7 @@ module.exports = UserEmailsController =
logger.log {userId, email, foundUserId: user?._id}, "email doesn't match logged in user"
return res.sendStatus 422
logger.log {userId, email}, 'resending email confirmation token'
UserEmailsConfirmationHandler.resendConfirmationEmail userId, email, (error) ->
UserEmailsConfirmationHandler.sendConfirmationEmail userId, email, (error) ->
return next(error) if error?
res.sendStatus 200