forked from arvention/ccapdev-session
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
56 lines (47 loc) · 1.46 KB
/
controller.js
File metadata and controls
56 lines (47 loc) · 1.46 KB
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
/*
defines an object which contains functions executed as callback
when a client requests for `index` paths in the server
*/
const controller = {
/*
executed when the client sends an HTTP GET request `/favicon.ico`
as defined in `../routes/routes.js`
*/
getFavicon: function (req, res) {
res.status(204);
},
/*
executed when the client sends an HTTP GET request `/`
as defined in `../routes/routes.js`
*/
getIndex: function (req, res) {
// checks if a user is logged-in by checking the session data
if(req.session.idNum) {
/*
redirects the client to `/profile` using HTTP GET,
defined in `../routes/routes.js`
passing values using URL
which calls getProfile() method
defined in `./profileController.js`
*/
res.redirect('/profile/' + req.session.idNum);
}
// else if a user is not yet logged-in
else {
/*
sets `details.flag` to false
to hide the profile and logout tabs in the nav bar
*/
var details = {
flag: false
};
// render `../views/index.hbs`
res.render('index', details);
}
}
}
/*
exports the object `controller` (defined above)
when another script exports from this file
*/
module.exports = controller;