-
-
Save matthewarkin/5851a9880d884a8625e1 to your computer and use it in GitHub Desktop.
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
//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