diff --git a/.env.example b/.env.example index f6d25ac..6374512 100644 --- a/.env.example +++ b/.env.example @@ -26,6 +26,10 @@ SMTP_AUTH_USERNAME= SMTP_AUTH_PASSWORD= EMAIL_TO= -USER_URL= -AUTH_URL= -CORS_ORIGIN= +USER_URL= +AUTH_URL= +SCORE_URL= + +CORS_ORIGIN= +VITE_USER_API= +VITE_AUTH_API= diff --git a/docker/front/compose.yml b/docker/front/compose.yml index 134b29d..a85d142 100644 --- a/docker/front/compose.yml +++ b/docker/front/compose.yml @@ -5,8 +5,8 @@ services: dockerfile: docker/front/Dockerfile context: ../../ args: - - VITE_USER_URL=${USER_URL} - - VITE_AUTH_URL=${AUTH_URL} + - VITE_USER_URL=${VITE_USER_URL} + - VITE_AUTH_URL=${VITE_AUTH_URL} environment: - TZ=Europe/Paris networks: diff --git a/src/front/static/ts/main.ts b/src/front/static/ts/main.ts index 5ac2396..35338a5 100644 --- a/src/front/static/ts/main.ts +++ b/src/front/static/ts/main.ts @@ -4,8 +4,11 @@ import FriendsMenu from "./views/Friends.ts"; let profile_view = new ProfileMenu; let friends_view = new FriendsMenu; +export const user_api = import.meta.env.VITE_USER_API as String; +export const auth_api = import.meta.env.VITE_AUTH_API as String; + export async function isLogged(): Promise { - let uuid_req = await fetch("http://localhost:3001/me", { + let uuid_req = await fetch(auth_api + "/me", { method: "GET", credentials: "include", }); @@ -129,7 +132,7 @@ function updateClock() async function pingClock() { if (await isLogged()) { - fetch(`http://localhost:3002/ping`, { + fetch(user_api + "/ping", { method: "POST", credentials: "include" }); diff --git a/src/front/static/ts/views/Friends.ts b/src/front/static/ts/views/Friends.ts index 7e11e4e..2d6d72a 100644 --- a/src/front/static/ts/views/Friends.ts +++ b/src/front/static/ts/views/Friends.ts @@ -1,7 +1,7 @@ import Aview from "./Aview.ts" -import { setOnekoState } from "../oneko.ts" import { dragElement } from "./drag.ts"; -import { isLogged, navigationManager } from "../main.ts" +import { setOnekoState } from "../oneko.ts" +import { isLogged, navigationManager, user_api, auth_api } from "../main.ts" export default class extends Aview { @@ -58,7 +58,7 @@ export default class extends Aview { const add_friend_msg = (document.getElementById("add-friend-msg") as HTMLParagraphElement); async function removeFriend(name: String) { - const data_req = await fetch("http://localhost:3002/users/" + uuid + "/friends/" + name, { + const data_req = await fetch(user_api + "/users/" + uuid + "/friends/" + name, { method: "DELETE", credentials: "include", }); @@ -76,7 +76,7 @@ export default class extends Aview { } async function isFriendLogged(name: string): Promise { - const data_req = await fetch("http://localhost:3002/ping/" + name, { + const data_req = await fetch(user_api + "/ping/" + name, { method: "GET", credentials: "include", }); @@ -88,7 +88,7 @@ export default class extends Aview { } const list_friends = async () => { - const data_req = await fetch("http://localhost:3002/users/" + uuid + "/friends/count", { + const data_req = await fetch(user_api + "/users/" + uuid + "/friends/count", { method: "GET", headers: { "Content-Type": "application/json", @@ -103,7 +103,7 @@ export default class extends Aview { } if (data.n_friends > 0) { - const list_req = await fetch("http://localhost:3002/users/" + uuid + "/friends?iStart=0&iEnd=2147483647", { + const list_req = await fetch(user_api + "/users/" + uuid + "/friends?iStart=0&iEnd=2147483647", { method: "GET", headers: { "Content-Type": "application/json", @@ -156,7 +156,7 @@ export default class extends Aview { } const add_friend = async () => { - const data_req = await fetch("http://localhost:3002/users/" + uuid + "/friends/" + new_friend.value, { + const data_req = await fetch(user_api + "/users/" + uuid + "/friends/" + new_friend.value, { method: "POST", credentials: "include", }); @@ -179,7 +179,7 @@ export default class extends Aview { } try { - const data_req = await fetch("http://localhost:3002/users/" + uuid + "/friends/count", { + const data_req = await fetch(user_api + "/users/" + uuid + "/friends/count", { method: "GET", headers: { "Content-Type": "application/json", diff --git a/src/front/static/ts/views/LoginPage.ts b/src/front/static/ts/views/LoginPage.ts index 2daecda..eaf49ca 100644 --- a/src/front/static/ts/views/LoginPage.ts +++ b/src/front/static/ts/views/LoginPage.ts @@ -1,7 +1,7 @@ import Aview from "./Aview.ts" import { dragElement } from "./drag.ts" import { setOnekoState } from "../oneko.ts" -import { isLogged, navigationManager } from "../main.ts" +import { isLogged, navigationManager, user_api, auth_api } from "../main.ts" export default class extends Aview { @@ -27,8 +27,10 @@ export default class extends Aview {

welcome back ! please login.

- - +
+ + +
@@ -37,13 +39,13 @@ export default class extends Aview {
@@ -53,6 +55,7 @@ export default class extends Aview { } async run() { + document.getElementById("login-google").href = `${auth_api}/login/google`; dragElement(document.getElementById("window")); const totpVerify = async () => { @@ -61,7 +64,7 @@ export default class extends Aview { const totpPin = (document.getElementById('totpPin') as HTMLInputElement).value; const idWindow = (document.getElementById('2fa-popup-content') as HTMLInputElement); try { - const data_req = await fetch("http://localhost:3001/login", { + const data_req = await fetch(auth_api + "/login", { method: "POST", headers: { "Content-Type": "application/json", }, credentials: "include", @@ -99,7 +102,7 @@ export default class extends Aview { const password = (document.getElementById("password") as HTMLInputElement).value; try { - const data_req = await fetch("http://localhost:3001/login", { + const data_req = await fetch(auth_api + "/login", { method: "POST", headers: { "Content-Type": "application/json", }, credentials: "include", @@ -163,9 +166,9 @@ export default class extends Aview { uu.disabled = true; pass.disabled = true; - document.getElementById("app")?.appendChild(popup); + document.getElementById("app")?.appendChild(popup); tokenInput.focus(); - dragElement(document.getElementById("2fa-popup")); + dragElement(document.getElementById("2fa-popup")); document.getElementById("totp-submit")?.addEventListener("click", totpVerify); } diff --git a/src/front/static/ts/views/Pong.ts b/src/front/static/ts/views/Pong.ts index 526812c..72aacf0 100644 --- a/src/front/static/ts/views/Pong.ts +++ b/src/front/static/ts/views/Pong.ts @@ -1,5 +1,5 @@ import Aview from "./Aview.ts" -import { isLogged } from "../main.js" +import { isLogged, user_api, auth_api } from "../main.js" import { dragElement } from "./drag.js" import { setOnekoState, setBallPos, setOnekoOffset } from "../oneko.ts" @@ -59,6 +59,9 @@ export default class extends Aview { let p1_name: string; let p2_name: string; + let p1_displayName: string; + let p2_displayName: string; + let countdown: number = 3; let countdownTimer: number = 0; @@ -148,7 +151,7 @@ export default class extends Aview { if (await isLogged()) { let uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; - fetch(`http://localhost:3002/users/${uuid}/matchHistory?game=pong`, { + fetch(user_api + "/users/" + uuid + "/matchHistory?game=pong", { method: "POST", headers: { "Content-Type": "application/json", }, credentials: "include", @@ -203,8 +206,8 @@ export default class extends Aview { ctx.font = "24px Kubasta"; let text_score = `${p1_score} - ${p2_score}`; ctx.fillText(text_score, canvas.width / 2 - (ctx.measureText(text_score).width / 2), 25); - ctx.fillText(p1_name, canvas.width / 4 - (ctx.measureText(p1_name).width / 2), 45); - ctx.fillText(p2_name, (canvas.width / 4 * 3) - (ctx.measureText(p2_name).width / 2), 45); + ctx.fillText(p1_displayName, canvas.width / 4 - (ctx.measureText(p1_name).width / 2), 45); + ctx.fillText(p2_displayName, (canvas.width / 4 * 3) - (ctx.measureText(p2_name).width / 2), 45); if (match_over) { @@ -273,23 +276,46 @@ export default class extends Aview { if (await isLogged()) { uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; - const userdata_req = await fetch(`http://localhost:3002/users/${uuid}`, { - method: "GET", - credentials: "include", - }); - if (userdata_req.status == 404) - { - console.error("invalid user"); - return ; - } - let userdata = await userdata_req.json(); - p1_input.value = userdata.displayName; + + p1_input.value = uuid; p1_input.readOnly = true; } else p1_input.value = "player 1"; - document.getElementById("game-start")?.addEventListener("click", () => { + document.getElementById("game-start")?.addEventListener("click", async () => { + let p1_isvalid = true; + let p2_isvalid = true; + if (await isLogged()) { + const p1_req = await fetch(`${user_api}/users/${p1_input.value}`, { + method: "GET", + credentials: "include", + }); + const p2_req = await fetch(`${user_api}/users/${p2_input.value}`, { + method: "GET", + credentials: "include", + }); + if (p1_req.status != 200) + p1_isvalid = false; + else + p1_displayName = (await p1_req.json()).displayName; + + if (p2_req.status != 200) + p2_isvalid = false; + else + p2_displayName = (await p2_req.json()).displayName; + } + else + p1_isvalid = p2_isvalid = false; + p1_name = p1_input.value; + p2_name = p2_input.value; + if (!p1_isvalid) + p1_displayName = p1_name; + if (!p2_isvalid) + p2_displayName = p2_name; + + p1_displayName = p1_displayName.length > 16 ? p1_displayName.substring(0, 16) + "." : p1_displayName; + p2_displayName = p2_displayName.length > 16 ? p2_displayName.substring(0, 16) + "." : p2_displayName; p1_name = p1_input.value.length > 16 ? p1_input.value.substring(0, 16) + "." : p1_input.value; p2_name = p2_input.value.length > 16 ? p2_input.value.substring(0, 16) + "." : p2_input.value; document.getElementById("player-inputs").remove(); diff --git a/src/front/static/ts/views/Profile.ts b/src/front/static/ts/views/Profile.ts index 6dce472..25258ab 100644 --- a/src/front/static/ts/views/Profile.ts +++ b/src/front/static/ts/views/Profile.ts @@ -1,7 +1,7 @@ import Aview from "./Aview.ts" import { dragElement } from "./drag.ts"; import { setOnekoState } from "../oneko.ts" -import { isLogged, navigationManager } from "../main.ts" +import { isLogged, navigationManager, user_api, auth_api } from "../main.ts" export default class extends Aview { @@ -49,7 +49,7 @@ export default class extends Aview { let uuid: String; uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; - const userdata_req = await fetch(`http://localhost:3002/users/${uuid}`, { + const userdata_req = await fetch(`${user_api}/users/${uuid}`, { method: "GET", credentials: "include", }); @@ -59,14 +59,14 @@ export default class extends Aview { } let userdata = await userdata_req.json(); - let matchCount_req = await fetch(`http://localhost:3002/users/${uuid}/matchHistory/count?game=pong`, { + let matchCount_req = await fetch(`${user_api}/users/${uuid}/matchHistory/count?game=pong`, { method: "GET", credentials: "include", }); let matchCount = await matchCount_req.json(); pc += matchCount.n_matches; - let matches_req = await fetch(`http://localhost:3002/users/${uuid}/matchHistory?game=pong&iStart=0&iEnd=${matchCount.n_matches}`, { + let matches_req = await fetch(`${user_api}/users/${uuid}/matchHistory?game=pong&iStart=0&iEnd=${matchCount.n_matches}`, { method: "GET", credentials: "include", }); @@ -78,6 +78,12 @@ export default class extends Aview { if (matches.matchHistory) { for (let match of matches.matchHistory) { + const p2_req = await fetch(`${user_api}/users/${match.score.p2}`, { + method: "GET", + credentials: "include", + }); + match.score.p1 = userdata.displayName; + match.score.p2 = (await p2_req.json()).displayName; const newEntry = document.createElement("li"); newEntry.classList.add("m-1", "default-button", "bg-neutral-200", "dark:bg-neutral-800", "text-neutral-900", "dark:text-white"); newEntry.innerHTML = match.score.p1Score > match.score.p2Score ? `${match.score.p1} - winner` : `${match.score.p2} - winner`; @@ -115,14 +121,14 @@ export default class extends Aview { } } - matchCount_req = await fetch(`http://localhost:3002/users/${uuid}/matchHistory/count?game=tetris`, { + matchCount_req = await fetch(`${user_api}/users/${uuid}/matchHistory/count?game=tetris`, { method: "GET", credentials: "include", }); matchCount = await matchCount_req.json(); pc += matchCount.n_matches; - matches_req = await fetch(`http://localhost:3002/users/${uuid}/matchHistory?game=tetris&iStart=0&iEnd=${matchCount.n_matches}`, { + matches_req = await fetch(`${user_api}/users/${uuid}/matchHistory?game=tetris&iStart=0&iEnd=${matchCount.n_matches}`, { method: "GET", credentials: "include", }); @@ -135,6 +141,15 @@ export default class extends Aview { // don't read this shit for you mental health if (matches.matchHistory) { for (let match of matches.matchHistory) { + if (match.score.p2 != undefined) + { + const p2_req = await fetch(`${user_api}/users/${match.score.p2}`, { + method: "GET", + credentials: "include", + }); + match.score.p2 = (await p2_req.json()).displayName; + } + match.score.p1 = userdata.displayName; const newEntry = document.createElement("li"); newEntry.classList.add("m-1", "default-button", "bg-neutral-200", "dark:bg-neutral-800", "text-neutral-900", "dark:text-white"); newEntry.innerHTML = match.score.p2 != undefined ? @@ -184,12 +199,12 @@ export default class extends Aview { if (!profile) return; const picture = profile.appendChild(document.createElement("img")); - const a = await fetch(`http://localhost:3002/users/${uuid}/avatar`, { + const a = await fetch(`${user_api}/users/${uuid}/avatar`, { method: "GET", credentials: "include", }); picture.src = a.status === 200 - ? `http://localhost:3002/users/${uuid}/avatar?t=${Date.now()}` + ? `${user_api}/users/${uuid}/avatar?t=${Date.now()}` : "https://api.kanel.ovh/pp"; picture.classList.add("text-neutral-900", "dark:text-white", "center", "h-18", "w-18", "mx-3", "reverse-border"); diff --git a/src/front/static/ts/views/ProfileMenu.ts b/src/front/static/ts/views/ProfileMenu.ts index 84422ca..9a480e0 100644 --- a/src/front/static/ts/views/ProfileMenu.ts +++ b/src/front/static/ts/views/ProfileMenu.ts @@ -1,5 +1,5 @@ import Aview from "./Aview.ts" -import { isLogged, navigationManager } from "../main.ts" +import { isLogged, user_api, auth_api } from "../main.ts" export default class extends Aview { async getHTML() { @@ -7,8 +7,7 @@ export default class extends Aview {
- -
girls kissing :3
+
knl_meowscendence
@@ -49,7 +48,7 @@ export default class extends Aview { document.getElementById("menu-bottom-div")?.classList.remove("hidden"); uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; - const userdata_req = await fetch(`http://localhost:3002/users/${uuid}`, { + const userdata_req = await fetch(`${user_api}/users/${uuid}`, { method: "GET", credentials: "include", }); @@ -68,19 +67,21 @@ export default class extends Aview { `; } - document.getElementById("profile-items").innerHTML = await getMainHTML(); - - document.getElementById("menu-logout")?.addEventListener("click", async () => { - let req = await fetch("http://localhost:3001/logout", { - method: "GET", - credentials: "include", + requestAnimationFrame(() => { + document.getElementById("menu-logout").addEventListener("click", async () => { + let req = fetch(`${auth_api}/logout`, { + method: "GET", + credentials: "include", + }); + req.then((res) => { + isLogged(); + if (res.status === 200) + this.run(); + else + console.error("logout failed"); + }); }); - isLogged(); - if (req.status === 200) - this.run(); - else - console.error("logout failed"); }); } } diff --git a/src/front/static/ts/views/RegisterPage.ts b/src/front/static/ts/views/RegisterPage.ts index 7485e93..ce19458 100644 --- a/src/front/static/ts/views/RegisterPage.ts +++ b/src/front/static/ts/views/RegisterPage.ts @@ -1,7 +1,7 @@ import Aview from "./Aview.ts" import { dragElement } from "./drag.ts"; import { setOnekoState } from "../oneko.ts" -import { isLogged, navigationManager } from "../main.ts" +import { isLogged, navigationManager, user_api, auth_api } from "../main.ts" export default class extends Aview { @@ -26,8 +26,10 @@ export default class extends Aview {

welcome ! please register.

- - +
+ + +
@@ -36,13 +38,13 @@ export default class extends Aview {
@@ -52,13 +54,14 @@ export default class extends Aview { } async run() { + document.getElementById("register-google").href = `${auth_api}/register/google`; dragElement(document.getElementById("window")); const login = async () => { const username = (document.getElementById("username") as HTMLInputElement).value; const password = (document.getElementById("password") as HTMLInputElement).value; try { - const data_req = await fetch("http://localhost:3001/register", { + const data_req = await fetch(auth_api + "/register", { method: "POST", headers: { "Content-Type": "application/json", }, credentials: "include", @@ -67,13 +70,12 @@ export default class extends Aview { const data = await data_req.json(); if (data_req.status === 200) { - let uuid_req = await fetch("http://localhost:3001/me", { + let uuid_req = await fetch(auth_api + "/me", { method: "GET", credentials: "include", }); let uuid = await uuid_req.json(); document.cookie = `uuid=${uuid.user};max-ages=${60 * 60 * 24 * 7}`; - console.log(document.cookie); isLogged(); navigationManager("/"); } diff --git a/src/front/static/ts/views/Settings.ts b/src/front/static/ts/views/Settings.ts index 3019af6..f2ab968 100644 --- a/src/front/static/ts/views/Settings.ts +++ b/src/front/static/ts/views/Settings.ts @@ -1,9 +1,9 @@ import Aview from "./Aview.ts" import { dragElement } from "./drag.ts"; import { setOnekoState } from "../oneko.ts" -import { isLogged, navigationManager } from "../main.ts" import { totpEnablePopup } from "./TotpEnable.ts"; import { totpVerify } from "../../../../api/auth/totpVerify.js"; +import { isLogged, navigationManager, user_api, auth_api } from "../main.ts" export default class extends Aview { @@ -53,7 +53,7 @@ export default class extends Aview { dragElement(document.getElementById("window")); const isTOTPEnabled = async () => { - const totpVerify_req = await fetch('http://localhost:3001/2fa', { + const totpVerify_req = await fetch(auth_api + '/2fa', { method: "GET", credentials: "include" }) @@ -66,10 +66,10 @@ export default class extends Aview { } return false; }; - + let uuid: String; uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; - const userdata_req = await fetch(`http://localhost:3002/users/${uuid}`, { + const userdata_req = await fetch(`${user_api}/users/${uuid}`, { method: "GET", credentials: "include", }); @@ -83,7 +83,7 @@ export default class extends Aview { (document.getElementById("displayName-input") as HTMLInputElement).value = userdata.displayName; document.getElementById("displayName-button")?.addEventListener("click", async () => { - const changeDisplayName_req = await fetch(`http://localhost:3002/users/${uuid}/displayName`, { + const changeDisplayName_req = await fetch(`${user_api}/users/${uuid}/displayName`, { method: "PATCH", headers: { "Content-Type": "application/json", }, credentials: "include", @@ -98,7 +98,7 @@ export default class extends Aview { }); document.getElementById("deleteAccount-button")?.addEventListener("click", async () => { - const delete_req = await fetch(`http://localhost:3001/`, { + const delete_req = await fetch(auth_api + "/", { method: "DELETE", credentials: "include", }); @@ -134,7 +134,7 @@ export default class extends Aview { }); (document.getElementById("upload-submit") as HTMLButtonElement).onclick = async () => { - const up_req = await fetch(`http://localhost:3002/users/${uuid}/avatar`, { + const up_req = await fetch(`${user_api}/users/${uuid}/avatar`, { method: "POST", headers: { "Content-Type": upload.files[0].type } , credentials: "include", @@ -142,14 +142,14 @@ export default class extends Aview { }); console.log(up_req.status); }; - + const totpButton = document.getElementById("2fa-button") as HTMLButtonElement; if ((await isTOTPEnabled()) === true) { totpButton.innerHTML = "disable 2fa"; document.getElementById("2fa-button")?.addEventListener("click", async () => { - const totp_req = await fetch(`http://localhost:3001/2fa`, { + const totp_req = await fetch(`${user_api}/2fa`, { method: "DELETE", credentials: "include" }) @@ -162,9 +162,9 @@ export default class extends Aview { }); } else { totpButton.innerHTML = "enable 2fa"; - + document.getElementById("2fa-button")?.addEventListener("click", async () => { - const totp_req = await fetch(`http://localhost:3001/2fa`, { + const totp_req = await fetch(`${user_api}/2fa`, { method: "POST", credentials: "include" }) diff --git a/src/front/static/ts/views/Tetris.ts b/src/front/static/ts/views/Tetris.ts index 72cfacb..496bbce 100644 --- a/src/front/static/ts/views/Tetris.ts +++ b/src/front/static/ts/views/Tetris.ts @@ -1,7 +1,7 @@ import Aview from "./Aview.ts"; -import { isLogged } from "../main.js"; import { dragElement } from "./drag.js"; import { setOnekoState, setBallPos, setOnekoOffset, setSleepPos } from "../oneko.ts"; +import { isLogged , user_api, auth_api } from "../main.js"; export default class extends Aview { running: boolean; @@ -630,7 +630,7 @@ export default class extends Aview { if (await isLogged()) { let uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; - fetch(`http://localhost:3002/users/${uuid}/matchHistory?game=tetris`, { + fetch(`${user_api}/users/${uuid}/matchHistory?game=tetris`, { method: "POST", headers: { "Content-Type": "application/json", }, credentials: "include", diff --git a/src/front/static/ts/views/TetrisVersus.ts b/src/front/static/ts/views/TetrisVersus.ts index 68f40e8..fbe83d0 100644 --- a/src/front/static/ts/views/TetrisVersus.ts +++ b/src/front/static/ts/views/TetrisVersus.ts @@ -1,5 +1,5 @@ import Aview from "./Aview.ts"; -import { isLogged } from "../main.js"; +import { isLogged, user_api, auth_api } from "../main.js"; import { dragElement } from "./drag.js"; import { setOnekoState, setBallPos, setOnekoOffset, setSleepPos } from "../oneko.ts"; @@ -66,6 +66,8 @@ export default class extends Aview { let p2_score: number = 0; let p1_name: string; let p2_name: string; + let p1_displayName: string; + let p2_displayName: string; const view = this; @@ -667,7 +669,7 @@ export default class extends Aview { if (await isLogged() && this.id == 0) { let uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; - fetch(`http://localhost:3002/users/${uuid}/matchHistory?game=tetris`, { + fetch(`${user_api}/users/${uuid}/matchHistory?game=tetris`, { method: "POST", headers: { "Content-Type": "application/json", }, credentials: "include", @@ -862,7 +864,7 @@ export default class extends Aview { ctx.fillRect(4, 4, 120, 60); ctx.fillStyle = "#fff"; ctx.font = "12px Kubasta"; - ctx.fillText(`${this.id == 0 ? p1_name : p2_name}: ${this.id == 0 ? p1_score : p2_score}`, 8, 20); + ctx.fillText(`${this.id == 0 ? p1_displayName : p2_displayName}: ${this.id == 0 ? p1_score : p2_score}`, 8, 20); ctx.fillText(`score: ${this.score}`, 8, 36); ctx.fillText(`lines: ${this.lines}`, 8, 52); @@ -933,26 +935,48 @@ export default class extends Aview { p2_input.value = "player 2"; if (await isLogged()) { - uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; - const userdata_req = await fetch(`http://localhost:3002/users/${uuid}`, { - method: "GET", - credentials: "include", - }); - if (userdata_req.status == 404) - { - console.error("invalid user"); - return ; - } - let userdata = await userdata_req.json(); - p1_input.value = userdata.displayName; + uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; + p1_input.value = uuid; p1_input.readOnly = true; } else p1_input.value = "player 1"; - document.getElementById("game-start")?.addEventListener("click", () => { - p1_name = p1_input.value.length > 16 ? p1_input.value.substring(0, 16) + "." : p1_input.value; - p2_name = p2_input.value.length > 16 ? p2_input.value.substring(0, 16) + "." : p2_input.value; + document.getElementById("game-start")?.addEventListener("click", async () => { + let p1_isvalid = true; + let p2_isvalid = true; + if (await isLogged()) { + const p1_req = await fetch(`${user_api}/users/${p1_input.value}`, { + method: "GET", + credentials: "include", + }); + const p2_req = await fetch(`${user_api}/users/${p2_input.value}`, { + method: "GET", + credentials: "include", + }); + if (p1_req.status != 200) + p1_isvalid = false; + else + p1_displayName = (await p1_req.json()).displayName; + + if (p2_req.status != 200) + p2_isvalid = false; + else + p2_displayName = (await p2_req.json()).displayName; + } + else + p1_isvalid = p2_isvalid = false; + + p1_name = p1_input.value; + p2_name = p2_input.value; + if (!p1_isvalid) + p1_displayName = p1_name; + if (!p2_isvalid) + p2_displayName = p2_name; + + p1_displayName = p1_displayName.length > 16 ? p1_displayName.substring(0, 16) + "." : p1_displayName; + p2_displayName = p2_displayName.length > 16 ? p2_displayName.substring(0, 16) + "." : p2_displayName; + document.getElementById("player-inputs").remove(); document.getElementById("game-boards").classList.remove("hidden"); game1 = new Game("board1", 0); diff --git a/src/front/static/ts/views/TotpEnable.ts b/src/front/static/ts/views/TotpEnable.ts index baf4fd9..51efed2 100644 --- a/src/front/static/ts/views/TotpEnable.ts +++ b/src/front/static/ts/views/TotpEnable.ts @@ -1,9 +1,9 @@ -import { navigationManager } from "../main.ts"; +import { navigationManager, user_api, auth_api } from "../main.ts"; import { dragElement } from "./drag.ts"; async function totpVerify() { const code = (document.getElementById("totpPin") as HTMLInputElement).value; - const data_req = await fetch('http://localhost:3001/2fa/verify', { + const data_req = await fetch(auth_api + '/2fa/verify', { method: "POST", credentials: "include", headers: { diff --git a/src/front/static/ts/views/TournamentMenu.ts b/src/front/static/ts/views/TournamentMenu.ts index 00538a8..03c246e 100644 --- a/src/front/static/ts/views/TournamentMenu.ts +++ b/src/front/static/ts/views/TournamentMenu.ts @@ -1,14 +1,17 @@ import Aview from "./Aview.ts" +import { isLogged, user_api } from "../main.js" import { dragElement } from "./drag.ts"; -import { setOnekoState, setBallPos } from "../oneko.ts" +import { setOnekoState, setBallPos, setOnekoOffset } from "../oneko.ts" export default class extends Aview { + running: boolean; constructor() { super(); this.setTitle("Tournament"); setOnekoState("default"); + this.running = true; } async getHTML() { @@ -23,7 +26,8 @@ export default class extends Aview {
-
+
+

how many players ?