From 7f6fd92abcb735041b902806071e0d0595cad2e9 Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Mon, 6 Dec 2021 11:27:15 -0700 Subject: [PATCH] Add proper redirects for PUBLIC_SUBMIT_PAGE variable --- routes/manage.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/routes/manage.js b/routes/manage.js index b1d8809..60e5b96 100644 --- a/routes/manage.js +++ b/routes/manage.js @@ -12,16 +12,32 @@ var accounts = require('../database/accounts/accounts'); var checkLoginStatus = require('./checkLoginStatus'); +if (process.env.NODE_ENV !== 'production' || process.env.NODE_ENV !== 'testing') { + require('dotenv').config(); +} + router.get('/' ,checkLoginStatus.user, function(req, res, next) { if(req.user[2]) res.render('manage', { title: 'Management Panel', userLoggedIn: !!req.user }); else res.render('manage/manage-nonadmin', { title: "My Games", userLoggedIn: !!req.user }); }); -router.get('/game', checkLoginStatus.user, function(req, res, next) { - let title = req.query.game ? 'Edit Game' : 'Submit Score' - - res.render('manage/addgame', { title, userLoggedIn: !!req.user, message: req.flash('error') }); +router.get('/game', function(req, res, next) { + if(!(process.env.PUBLIC_SUBMIT_PAGE && process.env.PUBLIC_SUBMIT_PAGE.toLowerCase() == 'true')) { + if (req.user) { + next(); + } + else { + res.redirect('/auth/login'); + }; + } else { + next(); + } + }, + function(req, res, next) { + let title = req.query.game ? 'Edit Game' : 'Submit Score' + + res.render('manage/addgame', { title, userLoggedIn: !!req.user, message: req.flash('error') }); }); router.post('/game', checkLoginStatus.user, async function(req, res, next) {