Better 404, and 404 on total-table if not logged

This commit is contained in:
Thomas Forgione 2017-09-26 11:49:03 +02:00
parent aa9ce199b0
commit f34475d211
No known key found for this signature in database
GPG Key ID: C75CD416BD1FFCE1
2 changed files with 17 additions and 1 deletions

View File

@ -1,3 +1,4 @@
const config = require('settings/config');
const cal = require('calendar');
const redirectIfNotLogged = require('auth/views').redirectIfNotLogged;
@ -38,7 +39,20 @@ module.exports.total = redirectIfNotLogged('total', function(req, res, render) {
render('total.pug');
});
module.exports.totalTable = function(req, res, render) {
module.exports.totalTable = function(req, res, render, next) {
if (req.session.user === undefined) {
res.status(404);
res.setHeader('Content-Type', 'text/html');
res.render(config.BASE_DIR + '/templates/404.pug', res.locals, function(err, result) {
if (err)
console.log(err);
res.send(result);
});
return;
}
computeUserTable(req.session.user, (result) => {
res.locals.courses = result.courses;
res.locals.total = result.total;

View File

@ -53,6 +53,8 @@ function startServer() {
// When route not found, raise not found
app.use(function(req, res) {
res.status(404);
res.setHeader('Content-Type', 'text/html');
res.render(config.BASE_DIR + '/templates/404.pug', res.locals, function(err, result) {