const express = require('express');
const User = require('../models/user').User;
const router = new express.Router();

const userController = require('../controllers/user');

/* GET users listing. */

router.get('/', isLoggedIn, userController.index);
router.get('/:id', isLoggedIn, userController.getUser);
router.get('/edit/:id', isLoggedIn, userController.editUser);
router.get('/edit/photo/:id', isLoggedIn, userController.photoUser);

// router.post('/edit/photo/:id', isLoggedIn, userController.editPhotoUser);

router.put('/edit/:id', isLoggedIn, userController.saveEditUser);

function isLoggedIn(req, res, next) {
  if (req.isAuthenticated()) return next();
  res.redirect('/login');
}

module.exports = router;
