Skip to content
Snippets Groups Projects
Commit 8e4b7229 authored by Lucas Gabriel Lima's avatar Lucas Gabriel Lima
Browse files

add checkage for all required fields before saving user

parent 58d3fdbd
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!25Auth
Pipeline #
......@@ -12,6 +12,8 @@ const User = require(`${libs}/models/user`);
const jwt = require('jwt-simple');
const required_fields = ["email", "password", "name", "cpf", "schooling", "course", "segment", "role", "institution_name", "state", "city"];
function emailSyntax(email) {
const regex = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
......@@ -19,8 +21,15 @@ function emailSyntax(email) {
}
userApp.post('/', (req, res, next) => {
if (!req.body.email || !req.body.password) {
res.json({success: false, msg: 'Please pass email and password.'});
if (!req.body.email) {
res.json({success: false, msg: 'Please pass email.'});
} else {
next();
}
}, (req, res, next) => {
if (!req.body.password) {
res.json({success: false, msg: 'Please pass password.'});
} else {
next();
}
......@@ -32,6 +41,14 @@ userApp.post('/', (req, res, next) => {
next();
}
}, (req, res, next) => {
for (let property of required_fields){
if(!Object.prototype.hasOwnProperty.call(req.body, property)){
res.json({success: false, msg: 'Please fill out all mandatory fields.'});
return;
}
}
next();
}, (req, res, next) => {
var newUser = new User({
email: req.body.email,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment