diff --git a/gambling.js b/gambling.js index f14e171..0c0a027 100644 --- a/gambling.js +++ b/gambling.js @@ -107,15 +107,15 @@ app.get("/", authenticateToken, (request, response) => { /* #swagger.security = [{ "bearerAuth": [] }] */ - response.sendFile(path.join(__dirname, "structure.png")); + response.sendFile(path.join(__dirname, ".\\public\\home.html")); }); -app.post("/balance", authenticateToken, (request, response) => { +app.get("/balance", authenticateToken, (request, response) => { /* #swagger.security = [{ "bearerAuth": [] }] */ const username = request.user.username; - + console.log(username); const allUsers = get_data(); const me = allUsers.find(u => u.username === username); @@ -123,7 +123,7 @@ app.post("/balance", authenticateToken, (request, response) => { return response.status(404).json({ error: "User not found" }); } - response.json({ balance: me.money }); + response.json({ balance: me.money }).status(200); }); app.post("/verify", authenticateToken, (request, response) => { diff --git a/lobby.js b/lobby.js new file mode 100644 index 0000000..983db7d --- /dev/null +++ b/lobby.js @@ -0,0 +1,20 @@ +const express = require("express"); +const app = express(); +const port = 3000; + +async function createLobby() { + let response = await fetch("https://www.deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1") + let data = await response.json(); + let lobbyId = data.deck_id + console.log(lobbyId); + return lobbyId; +} + +app.get("/lobby/create", async (req, res) => { + let lobbyId = await createLobby(); + res.send("Lobby ID: " + lobbyId); +}) + +app.listen(port, () => { + console.log("Server is running on port " + port); +}); diff --git a/public/frontend_home.js b/public/frontend_home.js new file mode 100644 index 0000000..6b5c1af --- /dev/null +++ b/public/frontend_home.js @@ -0,0 +1,19 @@ +document.addEventListener("DOMContentLoaded", async () => { + const logoutButton = document.getElementById("logout"); + const balance = document.getElementById("balance"); + try { + const balanceRes = await fetch('/balance', { + method: "GET", + headers: { + "Content-Type": "application/json", + } + }); + if (balanceRes.ok) { + const balanceData = await balanceRes.json(); + console.log(balanceData); + balance.innerHTML = balanceData.balance; + } + } catch (error) { + console.log(error); + } +}); \ No newline at end of file diff --git a/public/frontend.js b/public/frontend_login.js similarity index 91% rename from public/frontend.js rename to public/frontend_login.js index 1dfdad5..5382493 100644 --- a/public/frontend.js +++ b/public/frontend_login.js @@ -1,5 +1,4 @@ -const TokenHeader = new Headers(); -document.addEventListener("DOMContentLoaded", () => { +document.addEventListener("DOMContentLoaded", () => { const form = document.querySelector("form"); form.addEventListener("submit", async (e) => { @@ -20,6 +19,7 @@ document.addEventListener("DOMContentLoaded", () => { const loginData = await loginRes.json(); alert(`Welcome back, ${loginData.username}!`); document.cookie = `authorization=${loginData.token}` + window.location.href = "/"; return; } @@ -33,6 +33,7 @@ document.addEventListener("DOMContentLoaded", () => { const registerData = await registerRes.json(); alert(`Account created! Welcome, ${registerData.username}`); document.cookie = `authorization=${registerData.token}` + window.location.href = "/"; } else { const error = await registerRes.json(); alert("Register failed: " + (error.error || "Unknown error")); diff --git a/public/home.html b/public/home.html new file mode 100644 index 0000000..2fa4810 --- /dev/null +++ b/public/home.html @@ -0,0 +1,16 @@ + + + + + Home + + + + + + +
+ Balance: $0 +
+ + \ No newline at end of file diff --git a/public/login.html b/public/login.html index 704cd86..94bf5b2 100644 --- a/public/login.html +++ b/public/login.html @@ -3,7 +3,7 @@ Login - +
@@ -12,5 +12,5 @@
- + \ No newline at end of file diff --git a/public/nogger.html b/public/nogger.html deleted file mode 100644 index 0f87b5a..0000000 --- a/public/nogger.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - I am a Nogger Glace - - - - - \ No newline at end of file diff --git a/public/styles_home.css b/public/styles_home.css new file mode 100644 index 0000000..ca5ffd6 --- /dev/null +++ b/public/styles_home.css @@ -0,0 +1,53 @@ +body { + background: radial-gradient(circle at top, #111, #000); + color: #0f0; + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + margin: 0; + height: 100vh; + position: relative; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} + +body::before { + content: "♠ ♥ Welcome to Gambling API ♦ ♣"; + font-size: 24px; + color: #0f0; + margin-bottom: 40px; + display: block; + text-shadow: 0 0 5px #0f0, 0 0 10px #0f0; +} + +button { + background-color: #0f0; + color: #000; + border: none; + padding: 15px 30px; + font-size: 16px; + font-weight: bold; + border-radius: 12px; + cursor: pointer; + box-shadow: 0 0 10px #0f0, 0 0 5px #0f0 inset; + transition: background 0.2s ease-in-out, transform 0.2s; +} + +button:hover { + background-color: #1f1; + transform: scale(1.05); +} + +button.logout { + position: absolute; + top: 20px; + right: 20px; + padding: 10px 20px; + font-size: 14px; +} + +.balance { + margin-top: 20px; + color: #0f0; + text-shadow: 0 0 5px #0f0, 0 0 10px #0f0; +} \ No newline at end of file diff --git a/public/styles.css b/public/styles_login.css similarity index 100% rename from public/styles.css rename to public/styles_login.css