Skip to content

Commit 1f69a3b

Browse files
committedNov 5, 2018
First Commit
1 parent f61f7f4 commit 1f69a3b

16 files changed

+1222
-12
lines changed
 

‎angular.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"src/assets"
2424
],
2525
"styles": [
26-
"src/styles.css"
26+
"src/styles.css",
27+
"node_modules/bootstrap/dist/css/bootstrap.min.css",
28+
"node_modules/font-awesome/css/font-awesome.min.css"
2729
],
2830
"scripts": []
2931
},
@@ -132,4 +134,4 @@
132134
}
133135
},
134136
"defaultProject": "SportsStore"
135-
}
137+
}

‎authMiddleware.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const jwt = require("jsonwebtoken");
2+
const APP_SECRET = "myappsecret";
3+
const USERNAME = "admin";
4+
const PASSWORD = "secret";
5+
module.exports = function (req, res, next) {
6+
if ((req.url === "/api/login" || req.url === "/login")
7+
&& req.method === "POST") {
8+
if (req.body != null && req.body.name === USERNAME
9+
&& req.body.password === PASSWORD) {
10+
let token = jwt.sign({data: USERNAME, expiresIn: "1h"}, APP_SECRET);
11+
res.json({success: true, token: token});
12+
} else {
13+
res.json({success: false});
14+
}
15+
res.end();
16+
return;
17+
} else if ((((req.url.startsWith("/api/products")
18+
|| req.url.startsWith("/products"))
19+
|| (req.url.startsWith("/api/categories")
20+
|| req.url.startsWith("/categories"))) && req.method !== "GET")
21+
|| ((req.url.startsWith("/api/orders")
22+
|| req.url.startsWith("/orders")) && req.method !== "POST")) {
23+
let token = req.headers["authorization"];
24+
if (token != null && token.startsWith("Bearer<")) {
25+
token = token.substring(7, token.length - 1);
26+
try {
27+
jwt.verify(token, APP_SECRET);
28+
next();
29+
return;
30+
} catch (err) {
31+
}
32+
}
33+
res.statusCode = 401;
34+
res.end();
35+
return;
36+
}
37+
next();
38+
};

‎data.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module.exports = function () {
2+
return {
3+
products: [
4+
{
5+
id: 1, name: "Kayak", category: "Watersports",
6+
description: "A boat for one person", price: 275
7+
},
8+
{
9+
id: 2, name: "Lifejacket", category: "Watersports",
10+
description: "Protective and fashionable", price: 48.95
11+
},
12+
{
13+
id: 3, name: "Soccer Ball", category: "Soccer",
14+
description: "FIFA-approved size and weight", price: 19.50
15+
},
16+
{
17+
id: 4, name: "Corner Flags", category: "Soccer",
18+
description: "Give your playing field a professional touch",
19+
price: 34.95
20+
},
21+
{
22+
id: 5, name: "Stadium", category: "Soccer",
23+
description: "Flat-packed 35,000-seat stadium", price: 79500
24+
},
25+
{
26+
id: 6, name: "Thinking Cap", category: "Chess",
27+
description: "Improve brain efficiency by 75%", price: 16
28+
},
29+
{
30+
id: 7, name: "Unsteady Chair", category: "Chess",
31+
description: "Secretly give your opponent a disadvantage",
32+
price: 29.95
33+
},
34+
{
35+
id: 8, name: "Human Chess Board", category: "Chess",
36+
description: "A fun game for the family", price: 75
37+
},
38+
{
39+
id: 9, name: "Bling Bling King", category: "Chess",
40+
description: "Gold-plated, diamond-studded King", price: 1200
41+
}
42+
],
43+
orders: []
44+
}
45+
};

0 commit comments

Comments
 (0)