From aee72b358acd228e8fd364dadbb9157a1dc66f1d Mon Sep 17 00:00:00 2001
From: Lucas Gabriel Lima <lgl15@inf.ufpr.br>
Date: Thu, 20 Oct 2016 11:09:45 -0200
Subject: [PATCH] update API responses to match use cases's

---
 src/libs/routes/user.js | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/libs/routes/user.js b/src/libs/routes/user.js
index 9b24fbdc..2f410fbc 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.'});
                 }
             });
         }
-- 
GitLab