2015-05-22 12:04:39 +02:00
|
|
|
var tools = require('../../my_modules/filterInt');
|
2015-05-18 17:51:20 +02:00
|
|
|
var pg = require('pg');
|
2015-05-22 12:04:39 +02:00
|
|
|
var pgc = require('../../private');
|
|
|
|
var db = require('./dbrequests');
|
2015-05-20 11:17:14 +02:00
|
|
|
|
2015-05-05 11:56:35 +02:00
|
|
|
module.exports.index = function(req, res) {
|
|
|
|
res.setHeader('Content-Type', 'text/html');
|
|
|
|
|
2015-05-05 16:30:51 +02:00
|
|
|
res.render('index.jade', res.locals, function(err, result) {
|
2015-05-05 11:56:35 +02:00
|
|
|
res.send(result);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-05-22 12:04:39 +02:00
|
|
|
var protoHelper = function(template) {
|
|
|
|
return function(req, res) {
|
|
|
|
db.createId(function(id) {
|
|
|
|
req.session.user_id = id;
|
|
|
|
req.session.save();
|
2015-05-19 10:14:06 +02:00
|
|
|
|
2015-05-22 12:04:39 +02:00
|
|
|
res.setHeader('Content-Type','text/html');
|
|
|
|
res.render(template, res.locals, function(err, result) {
|
|
|
|
res.send(result);
|
|
|
|
});
|
2015-05-19 10:14:06 +02:00
|
|
|
});
|
2015-05-22 12:04:39 +02:00
|
|
|
};
|
2015-05-05 11:56:35 +02:00
|
|
|
}
|
|
|
|
|
2015-05-22 12:04:39 +02:00
|
|
|
module.exports.arrows = protoHelper('prototype_arrows.jade');
|
|
|
|
module.exports.viewports = protoHelper('prototype_viewports.jade');
|
|
|
|
module.exports.reverse = protoHelper('prototype_reverse.jade');
|
2015-05-19 15:43:09 +02:00
|
|
|
|
|
|
|
module.exports.replay_info = function(req, res) {
|
|
|
|
res.setHeader('Content-Type', 'text/plain');
|
|
|
|
|
|
|
|
// Parse id
|
|
|
|
var id = tools.filterInt(req.params.id);
|
|
|
|
|
2015-05-22 12:04:39 +02:00
|
|
|
db.getInfo(id, function(results) {
|
|
|
|
res.send(JSON.stringify(results));
|
2015-05-20 10:47:27 +02:00
|
|
|
});
|
2015-05-19 15:43:09 +02:00
|
|
|
}
|
|
|
|
|
2015-05-19 15:55:00 +02:00
|
|
|
module.exports.replay = function(req, res, next) {
|
2015-05-22 12:04:39 +02:00
|
|
|
// Get id parameter
|
2015-05-19 15:43:09 +02:00
|
|
|
res.locals.id = tools.filterInt(req.params.id);
|
|
|
|
|
2015-05-22 12:04:39 +02:00
|
|
|
db.checkId(res.locals.id, function(idExist) {
|
|
|
|
if (!idExist) {
|
|
|
|
var err = new Error("This replay does not exist");
|
|
|
|
err.status = 404;
|
|
|
|
next(err);
|
|
|
|
} else {
|
|
|
|
res.setHeader('Content-Type', 'text/html');
|
|
|
|
res.render('prototype_replays.jade', res.locals, function(err, result) {
|
|
|
|
res.send(result);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2015-05-19 15:43:09 +02:00
|
|
|
}
|
2015-05-20 11:17:14 +02:00
|
|
|
|
|
|
|
module.exports.replay_index = function(req, res, next) {
|
2015-05-22 12:04:39 +02:00
|
|
|
db.getAllUsers(function(result) {
|
|
|
|
res.locals.users = result;
|
|
|
|
|
|
|
|
res.setHeader('Content-Type', 'text/html');
|
2015-05-20 11:17:14 +02:00
|
|
|
res.render("replay_index.jade", res.locals, function(err, result) {
|
|
|
|
res.send(result);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2015-05-26 11:49:24 +02:00
|
|
|
|
|
|
|
module.exports.tutorial = function(req, res) {
|
|
|
|
|
|
|
|
|
|
|
|
res.setHeader('Content-Type', 'text/html');
|
|
|
|
res.render('tutorial.jade', res.lcals, function(err, result) {
|
|
|
|
res.send(result);
|
|
|
|
});
|
|
|
|
}
|