Created
September 6, 2012 15:30
-
-
Save erikthered/3657407 to your computer and use it in GitHub Desktop.
I suck at node :(
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
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