aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
authorkumar <kumar.damani@mail.utoronto.ca>2016-07-23 04:13:04 +0000
committerkumar <kumar.damani@mail.utoronto.ca>2016-07-23 04:13:04 +0000
commitf658b2367b9ea33703f3b4174688a96e682d86c8 (patch)
tree4d537a30f864625d00fb055f1672bb549456e9dd /routes
parent9ab4094797e82798eab40b32e7c71b52bb847b8f (diff)
parenteefeb25d3fabf377c09dd6c7282f0992eb1afea1 (diff)
pull
Merge branch 'master' of https://github.com/HumairAK/solutions_repo
Diffstat (limited to 'routes')
-rw-r--r--routes/admin.js49
-rw-r--r--routes/index.js21
-rw-r--r--routes/user.js8
3 files changed, 51 insertions, 27 deletions
diff --git a/routes/admin.js b/routes/admin.js
index c5cbcb4..35b208b 100644
--- a/routes/admin.js
+++ b/routes/admin.js
@@ -1,3 +1,4 @@
+var dbFile = require("../node_simple.js");
var express = require('express');
var router = express.Router();
var csrf = require('csurf'); // Cross-Site Request Forgery prevention
@@ -11,7 +12,7 @@ router.get('/', function(req,res){
});
/* Adds exam from front-end */
-router.post('/update/exam', function(req,res){
+router.post('/add/exam', function(req,res){
var course_code = req.body.course_code,
year = req.body.year,
type = req.body.type,
@@ -26,8 +27,8 @@ router.post('/update/exam', function(req,res){
var fields = [
course_code, // String
year, // Int
- type, // String; Needs to be added to database code
term, // String
+ type, // String
instructors, // Array of strings
page_count, // Int
questions_count, // Int
@@ -42,11 +43,11 @@ router.post('/update/exam', function(req,res){
}
console.log(statusMessage);
});
- res.redirect('/');
+ res.redirect('/admin');
});
/* Adds course from front-end */
-router.post('/update/course', function(req,res){
+router.post('/add/course', function(req,res){
var course_code = req.body.course_code,
title = req.body.title;
@@ -58,8 +59,46 @@ router.post('/update/course', function(req,res){
}
console.log("Status message: " + statusMessage)
});
- res.redirect('/');
+ res.redirect('/admin');
});
+router.post('/remove/exam', function(req,res){
+ var course_code = req.body.course_code,
+ year = req.body.year,
+ term = req.body.term,
+ type = req.body.type,
+ campus = req.body.campus;
+
+ var fields = [course_code, year, term, type];
+ console.log(fields);
+ dbFile.remove_exam(fields,
+ function(examRemoved, statusMessage){
+ if(examRemoved){
+ 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.
+ */
+function parseStringArray(input){
+ var list = input.split(',');
+ var parsedList = [];
+ list.forEach(function(word){
+ if (word != ""){
+ parsedList.push(word.trim());
+ }
+ });
+ return parsedList;
+}
+
module.exports = router;
diff --git a/routes/index.js b/routes/index.js
index 30189da..ac8e9a8 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -19,11 +19,11 @@ router.get('/user_solutions', function(req, res, next) {
res.render('user_solutions');
});
-/* Render/GET questions page */
+/* Render/GET questions page
router.get('/questions', function(req, res, next) {
res.render('questions');
});
-
+*/
//EXAMPLE EXPECTED DATA GIVEN BELOW:
/*[ {courseCode: 'CSC240',
@@ -86,8 +86,9 @@ router.get('/search', function(req, res, next) {
router.get('/questions/:exam_id', function (req,res) {
console.log(req.params.exam_id);
dbFile.get_exam_info_by_ID(req.params.exam_id, function (questions) {
- res.render('questions', {query: questions});
console.log(questions);
+ res.render('questions', {query: questions});
+
});
});
@@ -144,18 +145,4 @@ function toProperCase(string) {
return string.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
-/* Takes an input string delimited by commas, will split by comma and trim white
- * spaces. Consider callback.
- */
-function parseStringArray(input){
- var list = input.split(',');
- var parsedList = [];
- list.forEach(function(word){
- if (word != ""){
- parsedList.push(word.trim());
- }
- });
- return parsedList;
-}
-
module.exports = router; \ No newline at end of file
diff --git a/routes/user.js b/routes/user.js
index 840930a..014a7d2 100644
--- a/routes/user.js
+++ b/routes/user.js
@@ -49,10 +49,11 @@ router.post('/signup', loggedOut, function(req, res, next) {
req.check('password', "Password should be between 6 and 12 characters.")
.notEmpty().withMessage('Password required').isLength({min: 6, max: 12});
req.check('password', "The confirmation password doesn't match.").equals(req.body.confirmPassword);
+
+ // phone number optional
if (req.body.phone_num){
req.check('phone_num', 'Please enter a valid phone number').isMobilePhone('en-CA');
}
- // password has to be at least 4 characters long
var errors = req.validationErrors();
if (errors) {
@@ -68,14 +69,11 @@ router.post('/signup', loggedOut, function(req, res, next) {
})(req, res);
}
- //res.redirect('/signup');
-
});
router.post('/signin', loggedOut, function(req, res, next) {
req.check('usrname', 'Username field is empty.').notEmpty();
req.check('password', "Password field is empty.").notEmpty();
- // password has to be at least 4 characters long
var errors = req.validationErrors();
if (errors) {
@@ -89,9 +87,9 @@ router.post('/signin', loggedOut, function(req, res, next) {
failureRedirect: '/user/signin',
failureFlash: true
})(req, res);
-
}
+
});
module.exports = router;