var express = require('express'); var router = express.Router(); let JSONError = require('../helpers').JSONError; let Users = require('../database').Repositories.Users; /* GET users listing. */ router.get('/me', function(req, res, next) { console.log(req.user); res.send(req.user); }); /* 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) => { console.log(e); res.status(400); res.send(JSONError("Bad Credentials")); }); }); /* 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;