FlintSable
5/10/2017 - 10:49 PM

routes

routes

  app.post("/api/signup", function(req, res) {
    console.log(req.body);
    db.User.create({
      email: req.body.email,
      password: req.body.password
    }).then(function() {
      res.redirect(307, "/api/login");
    }).catch(function(err) {
      res.json(err);
    });
  });
router.get('/', function(req, res) {
    res.redirect('/home');
});

router.get('/home', function(req, res) {
    models.burgers.findAll().then(function(data){
    res.render('index', { indexData: data });
    });
});

router.post('/home/create', function(req, res) {
     models.users.create({
        user_name:req.body.name,
        email: req.body.email,
        phone: req.body.phone,
        disabled: 1
     }).then(function(){
        res.redirect('/home');
     });
});


router.put('/home/update/user/:id', function(req, res) {
   models.users.update({
    disabled: 0
    },{where:{
        id:req.params.id
    }}
   ).then(function(){
        res.redirect('/home');
   }) 
});

router.delete('/home/delete/:id', function(req, res) {
    models.users.destroy(
        {where:{
            id:req.params.id
        }}).then(function(){
            res.redirect('/home');
        })
})

router.use(function(req, res) {
    res.redirect('/home');
})

module.exports = router;
  app.get("/api/user_data", function(req, res) {
    if (!req.user) {
      // The user is not logged in, send back an empty object
      res.json({});
    }
    else {
      // Otherwise send back the user's email and id
      // Sending back a password, even a hashed password, isn't a good idea
      res.json({
        email: req.user.email,
        id: req.user.id
      });
    }
  });
 // Route for logging user out
  app.get("/logout", function(req, res) {
    req.logout();
    res.redirect("/");
  });