Created
November 23, 2012 19:42
-
-
Save deedubs/4137005 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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