1 let router
= require("express").Router();
2 const access
= require("../utils/access");
3 const UserModel
= require("../models/user");
4 const AssessmentModel
= require("../models/assessment");
5 const CourseModel
= require("../models/course");
7 // Actual pages (least specific last)
9 // List initials and count assessments
10 router
.get("/", (req
,res
) => {
11 UserModel
.getAll( (err
,userArray
) => {
22 router
.get("/login", access
.unlogged
, (req
,res
) => {
28 // Redirection screens when possible cheating attempt detected in exam
29 router
.get("/enablejs", (req
,res
) => {
30 res
.render("enablejs", {
35 router
.get("/fullscreen", (req
,res
) => {
36 res
.render("fullscreen", {
37 title: "Not in fullscreen",
41 router
.get("/noblur", (req
,res
) => {
42 res
.render("noblur", {
47 // List courses of some user (should be [a-z]+[0-9]* but fails...)
48 router
.get("/:initials([a-z0-9]+)", (req
,res
) => {
49 let initials
= req
.params
["initials"];
50 CourseModel
.getByInitials(initials
, (err
,courseArray
) => {
53 access
.getUser(req
, res
, (err2
,user
) => {
54 const isTeacher
= !!user
&& user
.initials
== initials
;
55 // Strip students from courses if not course admin (TODO: not required in any case)
58 courseArray
.forEach( c
=> {
62 res
.render("course-list", {
63 title: initials
+ " courses",
64 courseArray: courseArray
,
72 // Detailed content of one course
73 router
.get("/:initials([a-z0-9]+)/:courseCode([a-z0-9._-]+)", (req
,res
) => {
74 let initials
= req
.params
["initials"];
75 let code
= req
.params
["courseCode"];
76 CourseModel
.getByRefs(initials
, code
, (err
,course
) => {
77 access
.checkRequest(res
, err
, course
, "Course not found", () => {
78 AssessmentModel
.getByCourse(course
._id
, (err2
,assessmentArray
) => {
81 access
.getUser(req
, res
, (err2
,user
) => {
82 const isTeacher
= !!user
&& user
.initials
== initials
;
83 // Strip students from course if not course admin
85 delete course
["students"];
86 res
.render("course", {
87 title: "course " + initials
+ "/" + code
,
89 assessmentArray: assessmentArray
,
99 // Grading students answers: --> after identification (password), always send secret with requests
100 router
.get("/:initials([a-z0-9]+)/:courseCode([a-z0-9._-]+)/grade", (req
,res
) => {
101 let initials
= req
.params
["initials"];
102 let code
= req
.params
["courseCode"];
103 // TODO: if (main) teacher, also send secret, saving one request
104 res
.render("grade", {
105 title: "grade exams " + code
+ "/" + name
,
111 // Display assessment (exam or open status)
112 router
.get("/:initials([a-z0-9]+)/:courseCode([a-z0-9._-]+)/:assessmentName([a-z0-9._-]+)", (req
,res
) => {
113 let initials
= req
.params
["initials"];
114 let code
= req
.params
["courseCode"];
115 let name
= req
.params
["assessmentName"];
116 AssessmentModel
.getByRefs(initials
, code
, name
, (err
,assessment
) => {
117 access
.checkRequest(res
, err
, assessment
, "Assessment not found", () => {
118 if (!assessment
.active
)
119 return res
.json({errmsg: "Assessment is idle"});
120 delete assessment
["papers"]; //always remove recorded students answers
121 if (assessment
.mode
== "exam")
123 if (!!req
.headers
['user-agent'].match(/(SpecialAgent|HeadlessChrome|PhantomJS)/))
125 // Basic headless browser detection
126 return res
.json({errmsg: "Headless browser detected"});
128 // Strip questions if exam mode (stepwise process)
129 delete assessment
["questions"];
131 res
.render("assessment", {
132 title: "assessment " + initials
+ "/" + code
+ "/" + name
,
133 assessment: assessment
,
139 // Monitor: --> after identification (password), always send secret with requests
140 router
.get("/:initials([a-z0-9]+)/:courseCode([a-z0-9._-]+)/:assessmentName([a-z0-9._-]+)/monitor", (req
,res
) => {
141 let initials
= req
.params
["initials"];
142 let code
= req
.params
["courseCode"];
143 let name
= req
.params
["assessmentName"];
144 // TODO: if (main) teacher, also send secret, saving one request
145 res
.render("monitor", {
146 title: "monitor assessment " + code
+ "/" + name
,
153 module
.exports
= router
;