var express = require('express');
var router = express.Router();
const db = require('../models');
var User = db.User;
var Session = db.Session;

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('register');
});

router.post('/', async function(req, res, next) {
  console.log(req.body);
  if((req.body.username === '') || (req.body.email === '') || (req.body.password === '')) {
      res.redirect('/register');
  } else {
    var user = await User.create({
      name: req.body.username,
      email: req.body.email,
      password: req.body.password,
    });
    console.log(user);
    res.redirect('/login');
  }
});

module.exports = router;
