users.js 646 B

123456789101112131415161718192021222324252627282930
  1. var express = require('express');
  2. var router = express.Router();
  3. let JSONError = require('../helpers').JSONError;
  4. let Users = require('../database').Repositories.Users;
  5. /* GET users listing. */
  6. router.get('/', function(req, res, next) {
  7. res.send('respond with a resource');
  8. });
  9. /* GET users listing. */
  10. router.post('/login', function(req, res, next) {
  11. const params = {...req.body};
  12. const {
  13. username,
  14. password
  15. } = params;
  16. Users.login({username, password}).
  17. then((user) => res.send(user)).
  18. catch((e) => {
  19. console.log(e);
  20. res.status(400);
  21. res.send(JSONError("Bad Credentials"));
  22. });
  23. });
  24. module.exports = router;