Add proper redirects for PUBLIC_SUBMIT_PAGE variable

main
sudoer777 2021-12-06 11:27:15 -07:00
parent 06a7970fe7
commit 7f6fd92abc
1 changed files with 20 additions and 4 deletions

View File

@ -12,16 +12,32 @@ var accounts = require('../database/accounts/accounts');
var checkLoginStatus = require('./checkLoginStatus'); 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) { router.get('/' ,checkLoginStatus.user, function(req, res, next) {
if(req.user[2]) res.render('manage', { title: 'Management Panel', userLoggedIn: !!req.user }); 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 }); else res.render('manage/manage-nonadmin', { title: "My Games", userLoggedIn: !!req.user });
}); });
router.get('/game', checkLoginStatus.user, function(req, res, next) { router.get('/game', function(req, res, next) {
let title = req.query.game ? 'Edit Game' : 'Submit Score' if(!(process.env.PUBLIC_SUBMIT_PAGE && process.env.PUBLIC_SUBMIT_PAGE.toLowerCase() == 'true')) {
if (req.user) {
res.render('manage/addgame', { title, userLoggedIn: !!req.user, message: req.flash('error') }); 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) { router.post('/game', checkLoginStatus.user, async function(req, res, next) {