diff options
| -rw-r--r-- | node_simple.js | 9 | ||||
| -rw-r--r-- | package.json | 6 | ||||
| -rw-r--r-- | routes/admin.js | 32 | ||||
| -rw-r--r-- | routes/index.js | 15 | ||||
| -rw-r--r-- | routes/user.js | 4 | ||||
| -rw-r--r-- | views/admin.hbs | 24 |
6 files changed, 62 insertions, 28 deletions
diff --git a/node_simple.js b/node_simple.js index e798bd2..a3d0f6e 100644 --- a/node_simple.js +++ b/node_simple.js @@ -323,7 +323,8 @@ exports.retrieveFollows = function (user_name, callback) { /** * This function will retrieve ALL the comments a user has ever made. - * It returns an array containing objects of the form: {exam_id, comment, date}. + * It returns an array containing objects of the form: {exam_id, comment, date, ... + * course_code, year, term}. * Note: a comment should only exist IF a solution exists. * * @param {string} user_name: the unique user name for the user @@ -745,9 +746,9 @@ exports.add_comment = function (sol_id, fields, serverCallback) { } else { users.updateOne( { user_name: fields[1] }, { $inc: { comments: 1} }, function (err) { - if (err) callback(false, "Error: Some error occured while updating user info"); + if (err) serverCallback(false, "Error: Some error occured while updating user info"); else { - callback(true, "Success: comment added successfully"); + serverCallback(true, "Success: comment added successfully"); } }); @@ -1332,14 +1333,12 @@ exports.sendMail = function (mail_data, callback) { }); } - /* * * callback(success, error, data, message) * Returns the user's inbox (array of message objects) * */ - exports.checkMailbox = function (username, callback) { mongoFactory.getConnection(uri).then(function(db) { diff --git a/package.json b/package.json index 155e10d..2d21dcb 100644 --- a/package.json +++ b/package.json @@ -40,9 +40,7 @@ "passport-local": "^1.0.0", "promise": "^7.1.1", "sanitizer": "^0.1.3", - "socket.io": "^1.4.8" - }, - "devDependencies": { - "underscore": "~1.8.3" + "socket.io": "^1.4.8", + "underscore": "^1.8.3" } } diff --git a/routes/admin.js b/routes/admin.js index 7e5c7fe..027722d 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -86,6 +86,7 @@ router.post('/add/admin', function(req,res){ res.redirect('/admin'); }); +/* Remove an exam route, redirect to admin panel */ router.post('/remove/exam', function(req,res){ var course_code = req.body.course_code, year = req.body.year, @@ -108,6 +109,37 @@ router.post('/remove/exam', function(req,res){ res.redirect('/admin'); }); +/* Remove a course route, redirect to admin panel */ +router.post('/remove/course', function(req,res){ + var course_code = req.body.course_code; + dbFile.remove_course(course_code, function(courseRemoved, statusMessage){ + if(courseRemoved){ + console.log("Success."); + } else { + console.log("Failed."); + } + console.log(statusMessage); + }); + + res.redirect('/admin'); +}); + +/* Remove a user route, redirect to admin panel */ +router.post('/remove/user', function(req,res){ + var username = req.body.username; + dbFile.remove_user(username, function(userRemoved, statusMessage){ + if(userRemoved){ + console.log("Success."); + } else { + console.log("Failed."); + } + console.log(statusMessage); + }); + + res.redirect('/admin'); +}); + + /* Takes an input string delimited by commas, will split by comma and trim white * spaces. Consider callback. */ diff --git a/routes/index.js b/routes/index.js index 23cd7c3..698305b 100644 --- a/routes/index.js +++ b/routes/index.js @@ -29,12 +29,6 @@ router.get('/user_solutions', function(req, res, next) { res.render('user_solutions'); }); -/* Render/GET questions page -router.get('/questions', function(req, res, next) { - res.render('questions'); -}); -*/ - //EXAMPLE EXPECTED DATA GIVEN BELOW: /*[ {courseCode: 'CSC240', year: 2016, @@ -137,13 +131,6 @@ router.get('/questions/:exam_id', function (req,res) { res.render('questions', {query: qList, examInfo: examInfo}); }); }); - - /*dbFile.get_exam_info_by_ID(examID, function (questions) { - console.log(questions); - res.render('questions', {query: questions}); - - });*/ - }); /*GET the solutions for a given exam given the question number and the exam_id @@ -182,11 +169,9 @@ router.get('/questions/:exam_id', function (req,res) { */ router.get('/solutions/:exam_id/:q_num', function (req, res) { - console.log("index.js::Getting solutions"); var examID = req.params.exam_id; var qID = req.params.q_num; dbFile.get_all_solutions(examID, qID, function (solutions) { - console.log("index.js::GOT solutions"); solutions.forEach(function(soln){ soln.commentCount = soln.comments.length; }); diff --git a/routes/user.js b/routes/user.js index 4ba4dba..90e3b8d 100644 --- a/routes/user.js +++ b/routes/user.js @@ -285,6 +285,7 @@ router.post('/user_profile/send_message', loggedIn, function(req, res, next) { }); +// Authentication check in code router.post('/comment/submit/:examID/:qID/:solID', function(req, res, next){ var examID = req.params.examID; var qID = req.params.qID; @@ -292,7 +293,6 @@ router.post('/comment/submit/:examID/:qID/:solID', function(req, res, next){ var username = req.user.user_name; var solutionID = req.params.solID; // Must be a logged in user to access - console.log(examID + "," + qID + "," + comment + "," + username + "," + solutionID); var fields = [comment, username]; if(req.isAuthenticated()){ dbFile.add_comment(solutionID, fields, function(commentAdded, statusMessage){ @@ -310,7 +310,7 @@ router.post('/comment/submit/:examID/:qID/:solID', function(req, res, next){ } }); -router.post('/solution/vote/:examID/:qID/:solID', function(req, res, next){ +router.post('/solution/vote/:examID/:qID/:solID', loggedIn, function(req, res, next){ var vote = req.body.vote; var examID = req.params.examID; var qID = req.params.qID; diff --git a/views/admin.hbs b/views/admin.hbs index a260559..b821dc3 100644 --- a/views/admin.hbs +++ b/views/admin.hbs @@ -213,13 +213,33 @@ <!--- Remove Course ---> <div class="row cpnl-container" id="cpnl-removeCourse"> <h4>Remove Course</h4> - Pending. Need required database functionality. + <form action="/admin/remove/course" method="post"> + <div class="form-group"> + Course Code: <input type="text" + class="form-control" + placeholder="e.g. CSC240" + name="course_code"> + </div> + + <input type="hidden" name="_csrf" value="{{ csrfToken }}"> + <button type="submit" class="btn btn-primary">Submit</button> + </form> </div> <!--- Remove User ---> <div class="row cpnl-container" id="cpnl-removeUser"> <h4>Remove User</h4> - Pending. Need required database functionality. + <form action="/admin/remove/user" method="post"> + <div class="form-group"> + Username: <input type="text" + class="form-control" + placeholder="Jsmith85" + name="username"> + </div> + + <input type="hidden" name="_csrf" value="{{ csrfToken }}"> + <button type="submit" class="btn btn-primary">Submit</button> + </form> </div> |
