diff --git a/src/libs/routes/user.js b/src/libs/routes/user.js index 9b24fbdcb714051bb83b714d045ff6ef3de5896b..2f410fbcca146d4c48eaef6bfc0f255168d8aac2 100644 --- a/src/libs/routes/user.js +++ b/src/libs/routes/user.js @@ -150,8 +150,15 @@ userApp.post('/', (req, res, next) => { }); userApp.post('/authenticate', (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: 'O campo Email é obrigatório.'}); + } else { + next(); + } + +}, (req, res, next) => { + if (!req.body.password) { + res.json({success: false, msg: 'O campo Senha é obrigatório.'}); } else { next(); } @@ -163,7 +170,7 @@ userApp.post('/authenticate', (req, res, next) => { if (err) throw err; if(!user){ - res.json({success: false, msg: 'Authentication failed. User not found.'}); + res.json({success: false, msg: 'O Email informado não está cadastrado.'}); } else { user.comparePassword(req.body.password, (err, isMatch) => { @@ -174,10 +181,10 @@ userApp.post('/authenticate', (req, res, next) => { var token = jwt.encode(user, secret); //returns user info including token as json - res.json({success: true, token: 'JWT ' + token}); + res.json({success: true, token: 'JWT ' + token, msg: 'Usuário autenticado com sucesso'}); } else { - res.json({success: false, msg: 'Authentication failed. Wrong password'}); + res.json({success: false, msg: 'A Senha informada é inválida.'}); } }); }