aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--routes/index.js3
-rw-r--r--routes/user.js17
-rw-r--r--test/routingDb_tests.js6
-rw-r--r--views/layouts/layout.hbs7
-rw-r--r--views/questions.hbs25
5 files changed, 50 insertions, 8 deletions
diff --git a/routes/index.js b/routes/index.js
index 38f02fa..b3336dc 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -184,7 +184,8 @@ router.get('/questions/:exam_id', function (req,res) {
pageCount : exam.page_count,
questionCount : exam.questions_count
};
- res.render('questions', {query: qList, examInfo: examInfo});
+ res.render('questions', {query: qList, examInfo: examInfo, csrfToken: req.csrfToken()});
+ req.session.messages = null;
});
}else{
req.session.messages = {error : "Could not find exam."};
diff --git a/routes/user.js b/routes/user.js
index 5ddd4b8..74c5427 100644
--- a/routes/user.js
+++ b/routes/user.js
@@ -339,6 +339,23 @@ router.post('/solution/vote/:examID/:qID/:solID', function(req, res, next){
});
+router.post('/follow_exam/:examID',function (req, res) {
+
+ console.log("ENTERED THE FUNCTION FOLLOW EXAM!!");
+ var examId = req.params.examID;
+
+ if (req.isAuthenticated()){
+ console.log("Exam Id follow exam: " + examId);
+ console.log("Username follow exam: " + req.user.user_name);
+ }else{
+ var message = "Must be logged in to follow an exam!";
+ req.session.messages = {error : message};
+ res.redirect('/questions/' + examId);
+
+ }
+});
+
+
module.exports = router;
/************** Route protection ********************/
diff --git a/test/routingDb_tests.js b/test/routingDb_tests.js
index dd5fe44..d3a607f 100644
--- a/test/routingDb_tests.js
+++ b/test/routingDb_tests.js
@@ -332,7 +332,8 @@ describe('Solutions Route:', function(){
});
- /* COME BACK TO THIS AFTER GET_ALL_SOLUTIONS IS UPDATED*/
+ /* The path will render but an error message will be displayed
+ * To see error message, test false id on front end. */
it('Search solutions for a non existing exam', function testSlash(done) {
var qID = 1; //Check the first question
var examID = exams.nonExisting._id.$oid;
@@ -340,9 +341,6 @@ describe('Solutions Route:', function(){
.get('/solutions/' + examID + '/' + qID)
.end(function(err, res){
expect(res).to.have.status(200);
- // Check for expected url path
- var path = res.res.req.path;
- assert.equal(path, '/solutions/' + examID + '/' + qID);
done();
});
});
diff --git a/views/layouts/layout.hbs b/views/layouts/layout.hbs
index 62e9134..b9895a5 100644
--- a/views/layouts/layout.hbs
+++ b/views/layouts/layout.hbs
@@ -17,13 +17,16 @@
<!--Fonts-->
<link href='https://fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
- <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
-
+ <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css"
+ rel="stylesheet"
+ integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1"
+ crossorigin="anonymous">
<!--JS-->
<script src="/assets/js/jquery-2.2.4.min.js"></script>
<script src="/assets/js/bootstrap.min.js"></script>
<script src="/assets/js/script.js"></script>
+
</head>
<body>
{{> header }}
diff --git a/views/questions.hbs b/views/questions.hbs
index 4b40d33..1d62a2b 100644
--- a/views/questions.hbs
+++ b/views/questions.hbs
@@ -1,7 +1,30 @@
<main id = 'solutions-main'>
<div class = 'search container' id = 'solutions-div'>
- <!-- EXAM DETAILS -->
+ <!-- EXAM DETAILS -->
+ {{# if messages.error }}
+ <section class="alert alert-danger custom-Alert">
+ <h4>{{ messages.error }}</h4>
+ </section>
+ {{/if}}
+
+ <form action="/user/follow_exam/{{examInfo.id}}" method = 'post'>
+ <input type="hidden" name="_csrf" value="{{ csrfToken }}">
+ <button class="col-xs-4 col-sm-2 col-md-2 col-lg-2
+ col-xs-offset-4 col-sm-offset-5 col-md-offset-2
+ col-lg-offset-2 rounded" id="add-solution" type="submit">
+ <h3>Follow Exam</h3>
+ </button>
+ </form>
+
+ <!--<a href="/user/follow_exam/{{../examInfo.id}}">-->
+ <!--<button class="col-xs-4 col-sm-2 col-md-2 col-lg-2-->
+ <!--col-xs-offset-4 col-sm-offset-5 col-md-offset-2-->
+ <!--col-lg-offset-2 rounded" id="add-solution">-->
+ <!--<h3>Follow Exam</h3>-->
+ <!--</button>-->
+ <!--</a>-->
+
<a href="http://www.cs.toronto.edu/~fpitt/CSC148/20131/tests/test1-0101.pdf" target='_blank'><img src="/assets/images/exam.png" class='exam-img img-responsive exam-info'></a>