-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathindex.js
100 lines (79 loc) · 3.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const SessionHandler = require("./session");
const ProfileHandler = require("./profile");
const BenefitsHandler = require("./benefits");
const ContributionsHandler = require("./contributions");
const AllocationsHandler = require("./allocations");
const MemosHandler = require("./memos");
const ResearchHandler = require("./research");
const {
environmentalScripts
} = require("../../config/config");
const ErrorHandler = require("./error").errorHandler;
const index = (app, db) => {
"use strict";
const sessionHandler = new SessionHandler(db);
const profileHandler = new ProfileHandler(db);
const benefitsHandler = new BenefitsHandler(db);
const contributionsHandler = new ContributionsHandler(db);
const allocationsHandler = new AllocationsHandler(db);
const memosHandler = new MemosHandler(db);
const researchHandler = new ResearchHandler(db);
// Middleware to check if a user is logged in
const isLoggedIn = sessionHandler.isLoggedInMiddleware;
//Middleware to check if user has admin rights
const isAdmin = sessionHandler.isAdminUserMiddleware;
// The main page of the app
app.get("/", sessionHandler.displayWelcomePage);
// Login form
app.get("/login", sessionHandler.displayLoginPage);
app.post("/login", sessionHandler.handleLoginRequest);
// Signup form
app.get("/signup", sessionHandler.displaySignupPage);
app.post("/signup", sessionHandler.handleSignup);
// Logout page
app.get("/logout", sessionHandler.displayLogoutPage);
// The main page of the app
app.get("/dashboard", isLoggedIn, sessionHandler.displayWelcomePage);
// Profile page
app.get("/profile", isLoggedIn, profileHandler.displayProfile);
app.post("/profile", isLoggedIn, profileHandler.handleProfileUpdate);
// Contributions Page
app.get("/contributions", isLoggedIn, contributionsHandler.displayContributions);
app.post("/contributions", isLoggedIn, contributionsHandler.handleContributionsUpdate);
// Benefits Page
app.get("/benefits", isLoggedIn, benefitsHandler.displayBenefits);
app.post("/benefits", isLoggedIn, benefitsHandler.updateBenefits);
/* Fix for A7 - checks user role to implement Function Level Access Control
app.get("/benefits", isLoggedIn, isAdmin, benefitsHandler.displayBenefits);
app.post("/benefits", isLoggedIn, isAdmin, benefitsHandler.updateBenefits);
*/
// Allocations Page
app.get("/allocations/:userId", isLoggedIn, allocationsHandler.displayAllocations);
// Memos Page
app.get("/memos", isLoggedIn, memosHandler.displayMemos);
app.post("/memos", isLoggedIn, memosHandler.addMemos);
// Handle redirect for learning resources link
app.get("/learn", isLoggedIn, (req, res) => {
// Insecure way to handle redirects by taking redirect url from query string
return res.redirect(req.query.url);
});
// Handle redirect for learning resources link
app.get("/tutorial", (req, res) => {
return res.render("tutorial/a1", {
environmentalScripts
});
});
app.get("/tutorial/:page", (req, res) => {
const {
page
} = req.params
return res.render(`tutorial/${page}`, {
environmentalScripts
});
});
// Research Page
app.get("/research", isLoggedIn, researchHandler.displayResearch);
// Error handling middleware
app.use(ErrorHandler);
};
module.exports = index;