From 630c86aacf4594ffae2b13720e5b44f8b2557953 Mon Sep 17 00:00:00 2001 From: nanalelfe Date: Sat, 23 Jul 2016 07:52:04 -0400 Subject: Added route protection for the admin panel, and additional for user. Nav changes depending on admin/user --- routes/admin.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'routes/admin.js') diff --git a/routes/admin.js b/routes/admin.js index 35b208b..bdd4f9b 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -7,7 +7,9 @@ var passport = require('passport'); var csrfProtection = csrf(); router.use(csrfProtection); // router is protected -router.get('/', function(req,res){ + + +router.get('/', isAdmin, function(req,res){ res.render('admin', {csrfToken: req.csrfToken()}); }); @@ -102,3 +104,13 @@ function parseStringArray(input){ module.exports = router; + +/************** Route protection ********************/ + +function isAdmin(req, res, next) { + if (!req.user.email){ + return next(); + } + res.redirect('/'); +} + -- cgit v1.2.3