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) {