Added money
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
[
|
||||
{
|
||||
"username": "jerome",
|
||||
"password": "Sigma",
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Implcm9tZSIsImlhdCI6MTc0NDg3NDQ2MCwiZXhwIjoxNzQ0ODc2MjYwfQ.4FnQwoi25uSs8VQWBgC3MRvaZfqcoDN8041fky4YDo4",
|
||||
"money": 200
|
||||
},
|
||||
{
|
||||
"username": "Gianimon",
|
||||
"password": "gianimon",
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IkdpYW5pbW9uIiwiaWF0IjoxNzQ0ODc0NTczLCJleHAiOjE3NDQ4NzYzNzN9.dGp5WTKIDVhomKZ8J7nevz8O7PqwRhR9wEgeyDtL_XE",
|
||||
"money": 200
|
||||
},
|
||||
{
|
||||
"username": "any",
|
||||
"password": "any",
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFueSIsImlhdCI6MTc0NDg3OTQ1NCwiZXhwIjoxNzQ0ODgxMjU0fQ.xTV0yfMBO0BTsmggjouwYrx180un9rHiDljQqN6IUdw",
|
||||
"money": 200
|
||||
}
|
||||
]
|
||||
+18
-1
@@ -69,8 +69,9 @@ app.post("/register", (request, response) => {
|
||||
return response.status(400).json({ error: "Username already exists" });
|
||||
}
|
||||
|
||||
|
||||
const token = generateAccessToken({ username });
|
||||
saveUser({ username, password, token });
|
||||
saveUser({ username, password, token, "money": 200 });
|
||||
|
||||
response.json({ username, token });
|
||||
});
|
||||
@@ -102,6 +103,22 @@ app.get("/", authenticateToken, (request, response) => {
|
||||
response.sendFile(path.join(__dirname, "structure.png"));
|
||||
});
|
||||
|
||||
app.post("/balance", authenticateToken, (request, response) => {
|
||||
/* #swagger.security = [{
|
||||
"bearerAuth": []
|
||||
}] */
|
||||
const username = request.user.username;
|
||||
|
||||
const allUsers = get_data();
|
||||
const me = allUsers.find(u => u.username === username);
|
||||
|
||||
if (!me) {
|
||||
return response.status(404).json({ error: "User not found" });
|
||||
}
|
||||
|
||||
response.json({ balance: me.money });
|
||||
});
|
||||
|
||||
app.post("/verify", authenticateToken, (request, response) => {
|
||||
response.json({ valid: true, user: request.user });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user