aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-27 11:55:47 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-27 11:55:47 +0000
commita5528ed97fcd7d15c62effda4358ffea176548e0 (patch)
treede8568dd83e52e5b853eed35c664919cf3247956
parent91d29e0dcd03aa2d5d5170f2e713a79b395fa9eb (diff)
Added comments to admin.js
-rw-r--r--app.js2
-rw-r--r--routes/admin.js39
-rw-r--r--testImports.js159
3 files changed, 19 insertions, 181 deletions
diff --git a/app.js b/app.js
index 9832dcd..b0008a3 100644
--- a/app.js
+++ b/app.js
@@ -1,4 +1,3 @@
-var fs = require("fs");
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
@@ -31,7 +30,6 @@ app.set('view engine', 'hbs');
// Middleware initialization, make sure everything is initialized in proper order
app.use(compression());
-
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(expressValidator());
diff --git a/routes/admin.js b/routes/admin.js
index aac7c70..77594d5 100644
--- a/routes/admin.js
+++ b/routes/admin.js
@@ -9,6 +9,7 @@ app = express();
var csrfProtection = csrf();
router.use(csrfProtection); // router is protected
+/** Form validator */
app.use(express_validator({
customValidators:{
validRadio: function (value) {
@@ -33,14 +34,16 @@ app.use(express_validator({
}
}));
+/** Serve the main index.html page */
router.get('/', isAdmin, function(req,res){
- console.log(req.session.messages);
- res.render('admin', {adminPanel: true, csrfToken: req.csrfToken(), success: req.session.success, errors: req.session.errors});
+ res.render('admin', {adminPanel: true, csrfToken: req.csrfToken(), success: req.session.success,
+ errors: req.session.errors});
req.session.errors = null;
req.session.messages = null;
});
-/* Adds exam from front-end */
+
+/** Retrieves infomation from the exam adding form and sends it to the database to add. */
router.post('/add/exam', function(req,res){
req.sanitize('course_code').escape();
req.sanitize('course_code').trim();
@@ -75,7 +78,6 @@ router.post('/add/exam', function(req,res){
var errors = req.validationErrors();
if (errors){
- console.log(errors);
req.session.errors = errors;
req.session.success = false;
res.redirect('/admin');
@@ -109,13 +111,12 @@ router.post('/add/exam', function(req,res){
}else{
req.session.messages = {error : statusMsg};
}
- console.log(statusMsg);
res.redirect('/admin');
});
}
});
-/* Adds course from front-end */
+/** Retrieves information from the course adding form and sends it to the database to add. */
router.post('/add/course', function(req,res){
req.sanitize('course_code').escape();
@@ -129,7 +130,6 @@ router.post('/add/course', function(req,res){
var errors = req.validationErrors();
if (errors){
- console.log(errors);
req.session.errors = errors;
req.session.success = false;
res.redirect('/admin');
@@ -143,13 +143,12 @@ router.post('/add/course', function(req,res){
}else{
req.session.messages = {error : statusMsg};
}
- console.log(statusMsg);
res.redirect('/admin');
});
}
});
-/* Add a new admin, redirect to admin panel */
+/** Retrieves information from the admin user adding form and sends it to the database to add. */
router.post('/add/admin', function(req,res){
req.assert('fname', 'Please enter a valid first name.').notEmpty().withMessage('First name required.').isAlpha();
req.check('lname', 'Please enter a valid first name.').notEmpty().withMessage('Last name required.').isAlpha();
@@ -159,7 +158,6 @@ router.post('/add/admin', function(req,res){
var errors = req.validationErrors();
if (errors) {
- console.log(errors);
req.session.errors = errors;
req.session.success = false;
res.redirect('/admin');
@@ -177,7 +175,6 @@ router.post('/add/admin', function(req,res){
}else{
req.session.messages = {error : statusMsg};
}
- console.log(statusMsg);
res.redirect('/admin');
});
@@ -185,7 +182,7 @@ router.post('/add/admin', function(req,res){
});
-/* Remove an exam route, redirect to admin panel */
+/** Retrieves information from the exam removing form and sends it to the database to remove. */
router.post('/remove/exam', function(req,res){
req.sanitize('course_code').escape();
req.sanitize('course_code').trim();
@@ -202,7 +199,6 @@ router.post('/remove/exam', function(req,res){
var errors = req.validationErrors();
if (errors){
- console.log(errors);
req.session.errors = errors;
req.session.success = false;
res.redirect('/admin');
@@ -225,13 +221,13 @@ router.post('/remove/exam', function(req,res){
} else {
req.session.messages = {error : statusMsg};
}
- console.log(statusMsg);
res.redirect('/admin');
});
}
});
-/* Remove a course route, redirect to admin panel */
+
+/** Retrieves information from the course removing form and sends it to the database to delete. */
router.post('/remove/course', function(req,res){
req.sanitize('course_code').escape();
@@ -253,14 +249,13 @@ router.post('/remove/course', function(req,res){
} else {
req.session.messages = {error : statusMsg};
}
- console.log(statusMsg);
res.redirect('/admin');
});
}
});
-/* Remove a user route, redirect to admin panel */
+/** Retrieves information from the user adding form and sends it to the database to delete. */
router.post('/remove/user', function(req,res){
req.sanitize('username').trim();
@@ -280,7 +275,6 @@ router.post('/remove/user', function(req,res){
} else {
req.session.messages = {error : statusMsg};
}
- console.log(statusMsg);
res.redirect('/admin');
});
}
@@ -288,8 +282,13 @@ router.post('/remove/user', function(req,res){
});
-/* Takes an input string delimited by commas, will split by comma and trim white
- * spaces. Consider callback.
+/** Helper function */
+
+/**
+ * Takes an input string delimited by commas, will split by comma and trim whitespaces. Consider callback.
+ *
+ * @param input
+ * @returns {Array}
*/
function parseStringArray(input){
var list = input.split(',');
diff --git a/testImports.js b/testImports.js
deleted file mode 100644
index aa044e0..0000000
--- a/testImports.js
+++ /dev/null
@@ -1,159 +0,0 @@
-var dbFile = require("./node_simple");
-
-var fields = ["CSC240", 2016, "fall", "midterm", ["Faith Ellen", "Tom F."], 20, 2, "some date", "some user name"];
-var questions_array = ["this is q1", "this is q2"];
-
-
-// *****************************************************************************
-// EXAMPLE USAGE
-// *****************************************************************************
-
-
-// test adding of exams to the database functionality
-// dbFile.add_exam(fields, questions_array);
-
-//test removal of exam from the database functionality
-//dbFile.remove_exam([fields[0],fields[1],fields[2],fields[3]]);
-
-
-//test getting all exams database functionality -- USE FOR THE EXAMS PAGES maybe?
-/*dbFile.get_all_exams("CSC240", function (exams) {
- if (exams.length == 0){
- console.log("Nothing was found");
- }
- else {
- console.log(exams);
- }
- });*/
-
-//test adding course
-// dbFile.add_course("MAT237", "Advanced Calc", function (bool, mssg) {
-// console.log(mssg);
-// });
-
-//test adding solution
-/*dbFile.add_solution(["57917d4d2a73c0224fb6e763", 2, "this is another to q2", "kumar"], function (bool, mssg) {
-
- console.log(mssg);
-
- if (bool == true) {
- // do stuff
- }
-
- });*/
-
-/*dbFile.retrieve_userSolutions_history("some_user name", function (bool, result) {
- if (bool == false) {
- console.log(result);
- }
- else {
- console.log(result);
- }
- });*/
-
-/*dbFile.retrieve_userSolutions_count("some_user name", function (bool, result) {
- if (!bool) console.log(result);
- else { // bool is true i.e no error occured. result contains an integer
- console.log(result);
- }
- });*/
-
-dbFile.retrieve_userComments_history("kumar", function (bool, results) {
- if (!bool) console.log(results);
- else {
- console.log(results);
- }
- });
-
-/*dbFile.retrieve_userComments_count("sad@saddy.com", function (bool, result) {
- if (!bool) console.log(result);
- else { // bool is true i.e no error occured. result contains an integer
- console.log(result);
- }
- });*/
-
-
-// the following just prints the exam to console
-// dbFile.get_exam_byID("578a44ff71ed097fc3079d6e");
-
-//test getting all solutions of a given exam and question number
-//dbFile.get_all_solutions("578a44ff71ed097fc3079d6e", 1);
-
-
-//test adding of comments given a solution_id, and the comment information as an array
-/*dbFile.add_comment("5794c63ba930e20485a376a0", ["this is a comment to test updating user comments callback ", "kumar"], function (bool, mssg) {
- console.log(mssg);
- if (bool) {
- // do stuff
- }
- });*/
-
-
-/*
- dbFile.get_exam_info_by_ID("578a44ff71ed097fc3079d6e", function (result) {
- if (result.length == 0) {
- console.log("some error occured");
- }
- else {
- console.log(result);
- }
- });*/
-
-/*dbFile.add_user(["some as email", "some_user names", "kumar", "damani", "uofT", "cs", "some hashed passwd", "12312312312"], function (bool1, bool2, mssg) {
- console.log(mssg);
- });*/
-
-
-/*
- dbFile.find_user("some Email", function (result) {
- if (result == false) {
- console.log("no such user found");
- }
- else {
- console.log("user already exists");
- }
- });*/
-
-/* dbFile.find_user_name("some_user name", function (result) {
- if (result == false) {
- console.log("no such user_name found");
- }
- else {
- console.log("user_name taken");
- }
- });*/
-
-
-/*dbFile.followExam("nanalelfe@gmail.com", "578a44ff71ed097fc3079d6e", function (bool, mssg) {
- if (!bool) console.log(mssg);
- else {
- console.log(mssg);
- }
- });*/
-
-/*
- dbFile.retrieveFollows("some_user names", function (bool, result) {
- if (!bool) console.log(result);
- else {
- console.log(result);
- }
- });*/
-
-
-/*dbFile.vote_solution("5792d8a970040378d4e4b389" , "down", function (bool, mssg) {
- console.log(mssg);
- });*/
-
-
-/*dbFile.search_users("kumar", function (bool, mssg) {
- if (mssg.length != 0) console.log(mssg);
- });*/
-
-/*dbFile.remove_user("some_user name", function (bool, mssg) {
- console.log(mssg);
- });*/
-
-/*
-dbFile.remove_course("MAT237", function (bool, mssg) {
- console.log(mssg);
-});*/