var express = require('express');
var path = require('path');
var router = express.Router();
var uc = require('../controllers/users_controller');

var htmlPath = path.join(__dirname,'../../../','web/users/');

router.get('/', function(req, res) {
    if(!req.session.userAccount){
        res.redirect('/login');
    }
    else{
        res.redirect('/pm');
    }
});

router.get('/login', function(req, res) {
  res.render('users/login', {});
});

router.post('/login', uc.userLogin);

router.get('/reg', function(req, res, next) {
  res.render('reg',{});
});

router.post('/reg', uc.userReg);

router.get("/logout",function(req,res){
    delete req.session.userID;
    delete req.session.userAccount;
    delete req.session.userEmail;
    delete req.session.userMobile;
    res.redirect("/");
});

module.exports = router;