From f34475d211257ad1b7b848091e7e35f0effb1ed9 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Tue, 26 Sep 2017 11:49:03 +0200 Subject: [PATCH] Better 404, and 404 on total-table if not logged --- controllers/total/views.js | 16 +++++++++++++++- index.js | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/controllers/total/views.js b/controllers/total/views.js index 43087aa..bb7037d 100644 --- a/controllers/total/views.js +++ b/controllers/total/views.js @@ -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; diff --git a/index.js b/index.js index 1935e4f..f9466b8 100644 --- a/index.js +++ b/index.js @@ -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) {