var express = require('express'); var app = express(); var http = require('http').Server(app); var io = require('socket.io')(http); var mysql = require('mysql'); const util = require('util'); var bodyParser = require('body-parser'); var session = require('express-session'); var fonctionMaison = require('./fonction.js'); var registerController = require('./controllers/register-controller.js'); var loginController = require('./controllers/login-controller.js'); app.use(bodyParser.json()); // support json encoded bodies app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies app.use(session({ secret: 'fUZG4VjOx9U91Htq2AAA', cookie: { maxAge: 60000 }, saveUninitialized: true,resave: false})); const config = require('./config.json'); var con = require('./bdd.js') app.set('view engine', 'ejs'); app.use('/static/', express.static('static')); app.get('/', function(req, res){ if(req.session.authStatus) con.query('SELECT * FROM zone', function (err, result, fields) { if (err) throw err; var zone = JSON.stringify(result); zone = JSON.parse(zone); res.render('index', {zone:zone}); }); else res.redirect('/login'); }).get('/TV', function(req, res){ res.render('TV'); }).get('/TV/zone/:zone', function(req, res){ con.query("SELECT * FROM com_active INNER JOIN zone ON com_active.ID_Zone = zone.ID_Zone INNER JOIN communication ON com_active.ID_Com = communication.ID_Com WHERE zone.ID_Zone = ? ", [req.params.zone], function(err, result){ if (err) throw err; var pub = JSON.stringify(result); pub = JSON.parse(pub); fonctionMaison.listPubDansZone(req.params.zone,function(err, pub){ if (err) throw err; res.render('TV', {zone:req.params.zone,pub:pub}) }); }); }).get('/TV/latlng/:lat/:lng', function(req,res){ con.query('CALL cherche_zones(?,?,?,?)', [req.params.lat,req.params.lat,req.params.lng,req.params.lng], function(err, result){ if (err) throw err; var data = JSON.stringify(result); data = JSON.parse(data); var zone = fonctionMaison.choixZone(data[0]); fonctionMaison.listPubDansZone(zone,function(err, pub){ if (err) throw err; res.render('TV', {zone:zone.ID_Zone,pub:pub}) }); //console.log(util.inspect(data[0][0].Nom, false, null, true /* enable colors */)) }); }).get('/map', function(req, res){ con.query('SELECT * FROM zone', function (err, result, fields) { if (err) throw err; var zone = JSON.stringify(result); zone = JSON.parse(zone); res.render('map', {zone:zone}); }); }).get('/login', function(req, res){ res.render('login'); }).post('/login', loginController, function(req, res){ res.send('
'+req.session.authMessage+'