javascript - Validate request parameters in SailsJS -


in sailsjs, validate request parameters using same mechanism when models validated when model actions performed.

so when define model use "attributes" option specify parameter properties, , used validation.

but if you'd validate login form or email form on server side, there no model needed , you'd validate parameters?

so i'd able this:

//login validation req.validate({    email: { required: true, email: true },    password: { required: true } });  //send email validation req.validate({    subject: { required: true, type: 'string' },    to: { required: true, type: 'string' },    body: { required: true, type: 'string' } }); 

a function req.validate mixed in requests , called if req.options.usage set request, i've played bit don't quite understand it's doing. there no documentation on nor in "anchor" what's used validation.

any or suggestions on how achieve (preferably undocumented sailsjs feature)?

as per sailsjs docs model validations.

notes shorthand model.validate({ attributes }, cb) if .save() without first validating, waterline tries convert. if can't, throw error. in case, have converted array string 'marie,hank' there no parameters in callback unless there error. no news news. instance method. currently, instance methods not transactional. because of this, recommended use equivalent model method instead.

yourloginmodel.validate(req.body, function(err) {     console.log(json.stringify(err)); }); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -