aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-24 00:54:48 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-24 00:54:48 +0000
commitdbdcb21969ffd5540bd310b14ee2348adac24b5c (patch)
tree2dd748f9655cc147051e12aa5879174913204b4d /routes
parent17d743822746b047b94cd24e5407f1342ba01a7e (diff)
Added comments for user, along with dummy data if the user doesn't have any comments
Diffstat (limited to 'routes')
-rw-r--r--routes/admin.js2
-rw-r--r--routes/user.js42
2 files changed, 42 insertions, 2 deletions
diff --git a/routes/admin.js b/routes/admin.js
index e038fa3..5aa22fe 100644
--- a/routes/admin.js
+++ b/routes/admin.js
@@ -130,7 +130,7 @@ module.exports = router;
/************** Route protection ********************/
function isAdmin(req, res, next) {
- if (!req.user.email){
+ if (req.user && !req.user.email){
return next();
}
res.redirect('/');
diff --git a/routes/user.js b/routes/user.js
index 325b8ff..96cbd67 100644
--- a/routes/user.js
+++ b/routes/user.js
@@ -3,6 +3,8 @@ var router = express.Router();
var csrf = require('csurf'); // Cross-Site Request Forgery prevention
var passport = require('passport');
+var dbFile = require("../node_simple.js");
+
var csrfProtection = csrf();
router.use(csrfProtection); // router is protected
@@ -14,7 +16,45 @@ router.get('/logout', loggedIn, function (req, res, next) {
/* Render/GET user_profile page */
router.get('/user_profile', loggedIn, isUser, function(req, res, next) {
- res.render('user_profile_alt');
+ // GET COMMENTS
+ var comments = [];
+ dbFile.retrieve_userComments_history(req.user.user_name, function (success, object) {
+ if (!success) {
+ // Need to redirect to an error page instead.
+ console.log("Could not retrieve comments.");
+ } else if (object){
+ comments = object;
+ for (var comment in comments) {
+ dbFile.get_exam_byID(comment.exam_id, function(success, error, data) {
+ if (success) {
+ comment.exam_info = {
+ course_code : data.course_code,
+ term: data.term,
+ year : data.year
+ };
+ }
+ });
+ }
+
+ }
+ });
+ // For testing purposes, remove later:
+ if (!comments.length) {
+ var obj = {
+ comment: 'Use a heap!',
+ date: '2016-04-05',
+ exam_id: 'some id',
+ exam_info : {
+ course_code : 'CSC263',
+ term: 'Fall',
+ year : 2016
+ }
+ };
+ comments.push(obj);
+ comments.push(obj);
+ }
+
+ res.render('user_profile_alt', {comments : comments});
});
router.get('/signup', loggedOut, function(req, res, next) {