This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
forked from triplewy/security_lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benefits.js
106 lines (67 loc) · 2.56 KB
/
benefits.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
101
102
103
104
105
106
/********************************************************************************/
/* */
/* benefits.js */
/* */
/* Handle benefits pages */
/* */
/********************************************************************************/
/********************************************************************************/
/* */
/* Imports */
/* */
/********************************************************************************/
var db = require("./database.js");
/********************************************************************************/
/* */
/* Handle displaying the benefits page */
/* */
/********************************************************************************/
function displayBenefits(req,res,next)
{
displayBenefits0(req,res,next,false);
}
function displayBenefits0(req,res,next,succ)
{
var q = "SELECT * FROM User U WHERE U.isAdmin = FALSE";
db.query(q,function (e1,d1) { displayBenefits1(req,res,next,succ,e1,d1); } );
}
function displayBenefits1(req,res,next,succ,err,data)
{
if (err) return next(err);
for (var i = 0; i < data.rows.length; ++i) {
var date = data.rows[i].benefitStartDate;
var mon = date.getMonth() + 1;
if (mon < 10) mon = "0"+mon;
var string = date.getFullYear() + "-" + mon + "-" + date.getDate();
console.log("CONVERT",date,string);
data.rows[i].benefitStartDate = string;
}
var doc = { users : data.rows, user : { isAdmin : true } };
if (succ) doc.updateSuccess = true;
return res.render("benefits",doc);
}
/********************************************************************************/
/* */
/* Handle update benefits */
/* */
/********************************************************************************/
function updateBenefits(req,res,next)
{
var userid = req.body.userId;
var date = req.body.benefitStartDate;
var q = "UPDATE User SET benefitStartDate = '" + date + "' WHERE userId = " + userid;
db.query(q,function(e1,d1) { updateBenefits1(req,res,next,e1,d1); } );
}
function updateBenefits1(req,res,next,err,data)
{
if (err) return next(err);
return displayBenefits0(req,res,next,true);
}
/********************************************************************************/
/* */
/* Exports */
/* */
/********************************************************************************/
exports.displayBenefits = displayBenefits;
exports.updateBenefits = updateBenefits;
/* end of benefits.js */