Skip to content

Instantly share code, notes, and snippets.

@deedubs
Created November 23, 2012 19:42
Show Gist options
  • Save deedubs/4137005 to your computer and use it in GitHub Desktop.
Save deedubs/4137005 to your computer and use it in GitHub Desktop.
User.resetToken = function(user, callback) {
console.log('in generateResetToken')
User.findOne({email: user.email}, function(err, user) {
if(err) {
console.log('error')
res.send(500)
} else {
var sha = crypto.createHash('sha1');
console.log('sha ', sha)
sha.update((new Date()).toString() + user.email);
console.log('sha after update ', sha)
user.token = sha.digest('hex');
console.log('user.token ', user.token)
User.save(user, function(err, user) {
console.log('token after the save in the model ',user.token)
callback(err, user);
});
}
});
}
router.post('/recoverPassword', function (req, res) {
User
.findOne({ email: req.body.email }, function(err, user) {
if(err) {
res.send(500)
}
User.resetToken(user, function(err, user) {
console.log('new user token', user.token);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment