37b84cf7d852595ec2947457e65b1d3c1cb1b3b9
1 let router
= require("express").Router();
2 const access
= require("../utils/access");
3 const UserEntity
= require("../entities/user");
4 const AssessmentEntity
= require("../entities/assessment");
5 const CourseModel
= require("../models/course");
6 const AssessmentModel
= require("../models/assessment");
8 // Actual pages (least specific last)
10 // List initials and count assessments
11 router
.get("/", (req
,res
) => {
12 UserEntity
.getAll( (err
,userArray
) => {
23 router
.get("/login", access
.unlogged
, (req
,res
) => {
29 // Redirection screens when possible cheating attempt detected in exam
30 router
.get("/enablejs", (req
,res
) => {
31 res
.render("enable-js", {
36 router
.get("/nodevtools", (req
,res
) => {
37 res
.render("no-devtools", {
38 title: "Devtools enabled",
42 // List courses of some user (should be [a-z]+[0-9]* but fails...)
43 router
.get("/:initials([a-z0-9]+)", (req
,res
) => {
44 let initials
= req
.params
["initials"];
45 CourseModel
.getByInitials(initials
, (err
,courseArray
) => {
48 access
.getUser(req
, res
, (err2
,user
) => {
49 const isTeacher
= !!user
&& user
.initials
== initials
;
50 // Strip students from courses if not course admin (TODO: not required in any case)
53 courseArray
.forEach( c
=> {
57 res
.render("course-list", {
58 title: initials
+ " courses",
59 courseArray: courseArray
,
67 // Detailed content of one course
68 router
.get("/:initials([a-z0-9]+)/:courseCode([a-z0-9._-]+)", (req
,res
) => {
69 let initials
= req
.params
["initials"];
70 let code
= req
.params
["courseCode"];
71 CourseModel
.getByRefs(initials
, code
, (err
,course
) => {
72 access
.checkRequest(res
, err
, course
, "Course not found", () => {
73 AssessmentEntity
.getByCourse(course
._id
, (err2
,assessmentArray
) => {
76 access
.getUser(req
, res
, (err2
,user
) => {
77 const isTeacher
= !!user
&& user
.initials
== initials
;
78 // Strip students from course if not course admin
80 delete course
["students"];
81 res
.render("course", {
82 title: "course " + initials
+ "/" + code
,
84 assessmentArray: assessmentArray
,
94 // Display assessment (exam or open status)
95 router
.get("/:initials([a-z0-9]+)/:courseCode([a-z0-9._-]+)/:assessmentName([a-z0-9._-]+)", (req
,res
) => {
96 let initials
= req
.params
["initials"];
97 let code
= req
.params
["courseCode"];
98 let name
= req
.params
["assessmentName"];
99 AssessmentModel
.getByRefs(initials
, code
, name
, (err
,assessment
) => {
100 access
.checkRequest(res
, err
, assessment
, "Assessment not found", () => {
101 if (!assessment
.active
)
102 return res
.json({errmsg: "Assessment is idle"});
103 delete assessment
["papers"]; //always remove recorded students answers
104 if (assessment
.mode
== "exam")
106 if (!!req
.headers
['user-agent'].match(/(SpecialAgent|HeadlessChrome|PhantomJS)/))
108 // Basic headless browser detection
109 return res
.json({errmsg: "Headless browser detected"});
111 // Strip conclusion + questions if exam mode (stepwise process)
112 delete assessment
["conclusion"];
113 delete assessment
["questions"];
115 res
.render("assessment", {
116 title: "assessment " + initials
+ "/" + code
+ "/" + name
,
117 assessment: assessment
,
123 // Monitor: --> after identification (password), always send password hash with requests
124 router
.get("/:initials([a-z0-9]+)/:courseCode([a-z0-9._-]+)/:assessmentName([a-z0-9._-]+)/monitor", (req
,res
) => {
125 let initials
= req
.params
["initials"];
126 let code
= req
.params
["courseCode"];
127 let name
= req
.params
["assessmentName"];
128 res
.render("monitor", {
129 title: "monitor assessment " + code
+ "/" + name
,
136 module
.exports
= router
;