forked from cr0hn/vulnerable-node
-
Notifications
You must be signed in to change notification settings - Fork 2
/
products_patch.diff
58 lines (51 loc) · 1.39 KB
/
products_patch.diff
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
diff --git a/model/products.js b/model/products.js
index 6df3f92..9366003 100644
--- a/model/products.js
+++ b/model/products.js
@@ -49,12 +49,23 @@ function get_purcharsed(username) {
}
+function create(product) {
+ var q = "INSERT INTO products(name, description, price) VALUES('" +
+ product.name + "', '" +
+ product.description + "', '" +
+ product.price +
+ "');";
+
+ return db.one(q);
+}
+
var actions = {
"list": list_products,
"getProduct": getProduct,
"search": search,
"purchase": purchase,
- "getPurchased": get_purcharsed
+ "getPurchased": get_purcharsed,
+ "create": create
}
module.exports = actions;
diff --git a/routes/products.js b/routes/products.js
index 814f834..4d5d1fb 100644
--- a/routes/products.js
+++ b/routes/products.js
@@ -144,6 +144,24 @@ router.all('/products/buy', function(req, res, next) {
});
+router.all('/products/create', function(req, res, next) {
+ let params = null;
+ if (req.method == "GET"){
+ params = url.parse(req.url, true).query;
+ } else {
+ params = req.body;
+ }
+
+ let product = null;
+ product = {
+ name: params.name,
+ description: params.description,
+ price: params.price,
+ image: params.image,
+ username: req.session.user_name
+ }
+ db_products.create(product)
+});
module.exports = router;