Skip to content

Instantly share code, notes, and snippets.

@colinshen
Created January 2, 2015 10:07
Show Gist options
  • Save colinshen/22259e4b47b90a0842f0 to your computer and use it in GitHub Desktop.
Save colinshen/22259e4b47b90a0842f0 to your computer and use it in GitHub Desktop.
problem
//you see i console the all allParams in the create action. if i submit the form with empty value
//the comsole will be {username: '',email:'' .......}.i think if the value == '',this will directly return the badRequest to
//client. the problem is very strange.i did not write anything to stop the create.if the next() run, i should be run the User.create//(),right?because the form is empty, the User.create will throw the some error,like the username should not be empty.
//policy
module.exports = function(req, res, next) {
for(var value in req.allParams()){
if(value == ""){
console.log(value);
return res.badRequest('some input value is empty');
}
}
next();
};
//User controller
module.exports = {
create: function (req,res,next) {
console.log(req.allParams());
console.log(req.session);
User.create(req.allParams(),function (err,user) {
if(err)
return next(err);
console.log(user);
res.json(user);
})
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment