1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- var express = require('express');
- var router = express.Router();
- let JSONError = require('../helpers').JSONError;
- let Users = require('../database').Repositories.Users;
- /* GET users listing. */
- router.get('/', function(req, res, next) {
- res.send('respond with a resource');
- });
- /* 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;
|