From 9c10936cf1420f160a5007c6baad7b25ffb6d014 Mon Sep 17 00:00:00 2001 From: HumairAK Date: Tue, 26 Jul 2016 16:44:06 -0400 Subject: Added more unit tests, fixed some bugs in the code, fixed voting alert prompts and redirects --- routes/user.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'routes/user.js') diff --git a/routes/user.js b/routes/user.js index 39ffbf1..6e9815e 100644 --- a/routes/user.js +++ b/routes/user.js @@ -312,20 +312,29 @@ router.post('/comment/submit/:examID/:qID/:solID', function(req, res, next){ } }); -router.post('/solution/vote/:examID/:qID/:solID', loggedIn, function(req, res, next){ +router.post('/solution/vote/:examID/:qID/:solID', function(req, res, next){ var vote = req.body.vote; var examID = req.params.examID; var qID = req.params.qID; var solutionID = req.params.solID; - dbFile.vote_solution(solutionID, vote, function(voteCounted, statusMsg){ - if(voteCounted){ - console.log("Success!"); - }else{ - console.log("Action failed!"); - } - console.log(statusMsg); // Change to display message above + + if(req.isAuthenticated()){ + dbFile.vote_solution(solutionID, vote, function(voteCounted, statusMsg){ + if(voteCounted){ + res.redirect('/solutions/' + examID + '/' + qID); + }else{ + req.session.messages = {error : statusMsg}; + res.redirect('/solutions/' + examID + '/' + qID); + } + }); + } else { //User not logged in + var message = "Must be logged in to Vote!"; + req.session.messages = {error : message}; res.redirect('/solutions/' + examID + '/' + qID); - }); + } + + + }); -- cgit v1.2.3