f6c77a25d104066c3010954fdc326a783fa89be1
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("enablejs", {
36 router
.get("/fullscreen", (req
,res
) => {
37 res
.render("fullscreen", {
38 title: "Not in fullscreen",
42 router
.get("/noblur", (req
,res
) => {
43 res
.render("noblur", {
48 // List courses of some user (should be [a-z]+[0-9]* but fails...)
49 router
.get("/:initials([a-z0-9]+)", (req
,res
) => {
50 let initials
= req
.params
["initials"];
51 CourseModel
.getByInitials(initials
, (err
,courseArray
) => {
54 access
.getUser(req
, res
, (err2
,user
) => {
55 const isTeacher
= !!user
&& user
.initials
== initials
;
56 // Strip students from courses if not course admin (TODO: not required in any case)
59 courseArray
.forEach( c
=> {
63 res
.render("course-list", {
64 title: initials
+ " courses",
65 courseArray: courseArray
,
73 // Detailed content of one course
74 router
.get("/:initials([a-z0-9]+)/:courseCode([a-z0-9._-]+)", (req
,res
) => {
75 let initials
= req
.params
["initials"];
76 let code
= req
.params
["courseCode"];
77 CourseModel
.getByRefs(initials
, code
, (err
,course
) => {
78 access
.checkRequest(res
, err
, course
, "Course not found", () => {
79 AssessmentEntity
.getByCourse(course
._id
, (err2
,assessmentArray
) => {
82 access
.getUser(req
, res
, (err2
,user
) => {
83 const isTeacher
= !!user
&& user
.initials
== initials
;
84 // Strip students from course if not course admin
86 delete course
["students"];
87 res
.render("course", {
88 title: "course " + initials
+ "/" + code
,
90 assessmentArray: assessmentArray
,
100 // Display assessment (exam or open status)
101 router
.get("/:initials([a-z0-9]+)/:courseCode([a-z0-9._-]+)/:assessmentName([a-z0-9._-]+)", (req
,res
) => {
102 let initials
= req
.params
["initials"];
103 let code
= req
.params
["courseCode"];
104 let name
= req
.params
["assessmentName"];
105 AssessmentModel
.getByRefs(initials
, code
, name
, (err
,assessment
) => {
106 access
.checkRequest(res
, err
, assessment
, "Assessment not found", () => {
107 if (!assessment
.active
)
108 return res
.json({errmsg: "Assessment is idle"});
109 delete assessment
["papers"]; //always remove recorded students answers
110 if (assessment
.mode
== "exam")
112 if (!!req
.headers
['user-agent'].match(/(SpecialAgent|HeadlessChrome|PhantomJS)/))
114 // Basic headless browser detection
115 return res
.json({errmsg: "Headless browser detected"});
117 // Strip conclusion + questions if exam mode (stepwise process)
118 delete assessment
["conclusion"];
119 delete assessment
["questions"];
121 res
.render("assessment", {
122 title: "assessment " + initials
+ "/" + code
+ "/" + name
,
123 assessment: assessment
,
129 // Monitor: --> after identification (password), always send secret with requests
130 router
.get("/:initials([a-z0-9]+)/:courseCode([a-z0-9._-]+)/:assessmentName([a-z0-9._-]+)/monitor", (req
,res
) => {
131 let initials
= req
.params
["initials"];
132 let code
= req
.params
["courseCode"];
133 let name
= req
.params
["assessmentName"];
134 // TODO: if (main) teacher, also send secret, saving one request
135 res
.render("monitor", {
136 title: "monitor assessment " + code
+ "/" + name
,
143 module
.exports
= router
;