-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsuccessController.js
More file actions
66 lines (54 loc) · 2.02 KB
/
successController.js
File metadata and controls
66 lines (54 loc) · 2.02 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
57
58
59
60
61
62
63
64
65
66
/*
defines an object which contains functions executed as callback
when a client requests for `success` paths in the server
*/
const successController = {
/*
executed when the client sends an HTTP GET request `/success`
as defined in `../routes/routes.js`
*/
getSuccess: function (req, res) {
/*
when passing values using HTTP GET method
the values are stored in the req.query object
Example url: `http://localhost/success?fName=A&lName=B&idNum=123`
To retrieve the value of parameter `fName`: req.query.fName
*/
var details = {
fName: req.query.fName,
lName: req.query.lName,
idNum: req.query.idNum
};
// checks if a user is logged-in by checking the session data
if(req.session.idNum) {
/*
sets `details.flag` to true
to display the profile and logout tabs in the nav bar
sets the value of `details.name` to `req.session.name`
to display the name of the logged-in user
in the profile tab of the nav bar
sets the value of `details.uidNum` to `req.session.idNum`
to provide the link the profile of the logged-in user
in the profile tab of the nav bar
these values are rendered in `../views/partials/header.hbs`
*/
details.flag = true;
details.name = req.session.name;
details.uidNum = 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
*/
details.flag = false;
// render `../views/success.hbs`
res.render('success', details);
}
}
/*
exports the object `successController` (defined above)
when another script exports from this file
*/
module.exports = successController;