Quellcode durchsuchen

Users login/register

Nik Atlas vor 6 Jahren
Ursprung
Commit
c5b7f71d68
1 geänderte Dateien mit 19 neuen und 2 gelöschten Zeilen
  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;