Created
March 5, 2015 21:27
-
-
Save marcellodesales/5220e537bed04a7b7231 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Confirm the new user by retrieving the password submitted. | |
User.confirmNewUser = function(id, code, submittedUser, next) { | |
console.log("Submitted User ID: " + id + "; Data to confirm: " + JSON.stringify(submittedUser)); | |
// Find the user by ID submitted | |
// http://docs.strongloop.com/display/public/LB/Exposing+models+over+REST | |
User.findById(id, function (err, savedUser) { | |
if (err) { | |
throw err; | |
} | |
// Validate if the submitted code is correct from the user based on his/her email. | |
var savedMd5 = crypto.createHash('md5').update(savedUser.email).digest('hex').substring(0, 5); | |
console.log("INFO: Verifying if the code is correct: " + code + " = " + savedMd5); | |
if (savedMd5 !== code) { | |
console.log("ERROR: The confirmation code is incorrect: " + code + " != " + savedMd5); | |
throw new Error("ERROR: The confirmation code is incorrect: " + code + " != " + savedMd5); | |
} | |
console.log("Current User: ", savedUser.toObject()); | |
savedUser.password = submittedUser.password; | |
// Save the instance | |
savedUser.save(); | |
next(); | |
}); | |
}; |
This file contains hidden or 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
Browse your REST API at http://0.0.0.0:3000/explorer | |
Web server listening at: http://0.0.0.0:3000/ | |
Submitted User ID: 1; Data to confirm: {"password":"23234dsdsd34"} | |
INFO: Verifying if the code is correct: ee23 = 792a8 | |
ERROR: The confirmation code is incorrect: ee23 != 792a8 | |
/home/mdesales/dev/users-service/common/models/user.js:75 | |
throw new Error("ERROR: The confirmation code is incorrect: " + code | |
^ | |
Error: ERROR: The confirmation code is incorrect: ee23 != 792a8 | |
at /home/mdesales/dev/users-service/common/models/user.js:75:16 | |
at /home/mdesales/dev/users-service/node_modules/loopback-datasource-juggler/lib/dao.js:865:5 | |
at /home/mdesales/dev/users-service/node_modules/loopback-datasource-juggler/lib/dao.js:840:7 | |
at /home/mdesales/dev/users-service/node_modules/loopback-datasource-juggler/lib/connectors/memory.js:345:7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment