Forráskód Böngészése

Users login/register

Nik Atlas 6 éve
szülő
commit
c5b7f71d68
1 módosított fájl, 19 hozzáadás és 2 törlés
  1. 19 2
      routes/users.js

+ 19 - 2
routes/users.js

@@ -10,14 +10,14 @@ router.get('/', function(req, res, next) {
 });
 
 
-/* GET users listing. */
+/* post users login. */
 router.post('/login', function(req, res, next) {
   const params = {...req.body};
   const {
   	username,
   	password
   } = params;
-
+  console.log(username);
   Users.login({username, password}).
   then((user) => res.send(user)).
   catch((e) => {
@@ -27,4 +27,21 @@ router.post('/login', function(req, res, next) {
   });
 });
 
+/* post users register. */
+router.post('/register', function(req, res, next) {
+  const params = {...req.body};
+  const {
+  	username,
+  	password
+  } = params;
+  console.log(username);
+  Users.register({username, password}).
+  then((user) => res.send(user)).
+  catch((e) => {
+  	console.log(e);
+  	res.status(400);
+  	res.send(JSONError("Bad Credentials"));
+  });
+});
+
 module.exports = router;