Skip to content

Instantly share code, notes, and snippets.

@matthewarkin
Forked from colinshen/gist:22259e4b47b90a0842f0
Last active August 29, 2015 14:12
Show Gist options
  • Save matthewarkin/5851a9880d884a8625e1 to your computer and use it in GitHub Desktop.
Save matthewarkin/5851a9880d884a8625e1 to your computer and use it in GitHub Desktop.
//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