Skip to content

Instantly share code, notes, and snippets.

@erikthered
Created September 6, 2012 15:30
Show Gist options
  • Save erikthered/3657407 to your computer and use it in GitHub Desktop.
Save erikthered/3657407 to your computer and use it in GitHub Desktop.
I suck at node :(
function findUser(login, callback){
var collection = db.collection("users");
return collection.findOne({"login":login}, function(err, doc){
callback(null, doc);
});
}
// Try to find user based on login param
findUser(req.params.login, function(err,user){
var message = "Default message";
if(!user){
message = "Incorrect login/password";
resp.send(200, message);
return next();
}else{
// If user is found, test submitted password with bcrypt
bcrypt.compare(req.params.password, user.password, function(err, res){
if(res){
message = "Successful login!";
}else{
message = "Incorrect login/password";
}
// Send response with appropriate message
resp.send(200,message);
return next();
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment