diff options
| author | HumairAK <humair88@hotmail.com> | 2016-07-26 20:44:06 +0000 |
|---|---|---|
| committer | HumairAK <humair88@hotmail.com> | 2016-07-26 20:44:06 +0000 |
| commit | 9c10936cf1420f160a5007c6baad7b25ffb6d014 (patch) | |
| tree | d3fb09efa5dc25cfe63eb6c4c783f415cba45597 /routes/user.js | |
| parent | 3983edb2518acd91f991ad5fc6308bcaf46700f5 (diff) | |
Added more unit tests, fixed some bugs in the code, fixed voting alert prompts and redirects
Diffstat (limited to 'routes/user.js')
| -rw-r--r-- | routes/user.js | 27 |
1 files changed, 18 insertions, 9 deletions
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); - }); + } + + + }); |
