forked from triplewy/security_lab
-
Notifications
You must be signed in to change notification settings - Fork 1
/
memos.js
78 lines (48 loc) · 1.71 KB
/
memos.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
/********************************************************************************/
/* */
/* memos.js */
/* */
/* Handle memos pages */
/* */
/********************************************************************************/
var db = require("./database.js");
/********************************************************************************/
/* */
/* Hnadle adding a memo */
/* */
/********************************************************************************/
function addMemos(req,res,next)
{
var memo = req.body.memo;
var q = "INSERT INTO Memos(memo) VALUES ( '" + memo + "' )";
db.query(q,function(e1,d1) { addMemos1(req,res,next,e1,d1); });
}
function addMemos1(req,res,next,err,data)
{
if (err) return next(err);
displayMemos(req,res,next);
}
/********************************************************************************/
/* */
/* Handle displaying memos */
/* */
/********************************************************************************/
function displayMemos(req,res,next)
{
var q = "SELECT * FROM Memos ORDER BY memotime DESC";
db.query(q,function (e1,d1) { displayMemos1(req,res,next,e1,d1); } );
}
function displayMemos1(req,res,next,err,data)
{
if (err) next(err);
var doc = { memosList: data.rows, userId : req.session.userId };
return res.render("memos",doc);
}
/********************************************************************************/
/* */
/* Exports */
/* */
/********************************************************************************/
exports.addMemos = addMemos;
exports.displayMemos = displayMemos;
/* end of memos.js */