Answer the question
In order to leave comments, you need to log in
Why does a post request for this feature work 50/50?
app.post('/login', UserController.handlers.login);
login: function(req, res){
var mail = req.body.mail;
var password = req.body.password;
async.waterfall([
function(callback){
User.findOne({mail : mail}, callback );
},
function(user, callback){
if (user){
if (user.checkPassword(password)){
req.session.user = user._id;
result= {"login":"yes"};
}
else{
result= {"login":"no"}
}
}
else{
result = {"User": "notFound"};
}
callback(null, result);
}
], function (err, result) {
res.json(result);
});
Answer the question
In order to leave comments, you need to log in
Most likely this is because User.findOne({mail : mail}, callback); returns an error in callback and waterfall does not go further, i.e. the second function is not executed, but the final one is immediately called. It is not entirely clear what "does not work" means, what exactly is happening? Hangs and falls off on a timeout? What can be seen from the browser (firebug, developertools)? What http code returns or just breaks the connection? I advise you to form the result already in the final function, and only prepare data for this in the waterfall function array.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question