From cf2b59b75143ecbf716783e0e8992542c4a19102 Mon Sep 17 00:00:00 2001 From: Arek Date: Fri, 10 Jun 2022 12:23:44 +0200 Subject: [PATCH] feat: :sparkles: logout button now you can easy logout --- frontend/app.js | 32 +++++++++++- frontend/index.html | 5 +- .../dodawanie turnieju/app.js | 49 ++++++++++++++++--- .../dodawanie turnieju/index.html | 12 +++-- frontend/panel_organizatora/logowanie/app.js | 41 ++++++++++------ 5 files changed, 110 insertions(+), 29 deletions(-) diff --git a/frontend/app.js b/frontend/app.js index bd74503..ccaede2 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -11,15 +11,16 @@ async function showTournaments() { async function renderTournaments() { let tournaments = await showTournaments(); let html = ''; + console.log(tournaments) tournaments.forEach(tournament => { - let htmlSegment = `
+ let htmlSegment = `

${tournament.name}

- Propadel, Warszawa + ${tournament.place} ${tournament.from} do ${tournament.to}
@@ -32,3 +33,30 @@ async function renderTournaments() { let container = document.querySelector('.tournament-list'); container.innerHTML = html; } + +function logout() { + localStorage.clear(); + location.reload(); +} + +function logoutVisibility() { + if (localStorage.getItem("token") !== null) { + document.getElementById("logout").style.display = ""; + } + else { + document.getElementById("logout").style.display = "none"; + + } + +} + + +function loginVisibility() { + if (localStorage.getItem("token") !== null) { + document.getElementById("login").style.display = "none"; + } + else { + document.getElementById("login").style.display = ""; + + } +} \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html index 50d12ad..cf2a5ea 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -10,7 +10,7 @@ - +
@@ -18,10 +18,11 @@
diff --git a/frontend/panel_organizatora/dodawanie turnieju/app.js b/frontend/panel_organizatora/dodawanie turnieju/app.js index 8269ff2..672d97a 100644 --- a/frontend/panel_organizatora/dodawanie turnieju/app.js +++ b/frontend/panel_organizatora/dodawanie turnieju/app.js @@ -38,14 +38,24 @@ function createTournament() { body: JSON.stringify( { "name": document.getElementById("name").value, - "place": document.getElementById("place").value, - "ranked": document.getElementById("rank").value, + "typeOfLadder": "string", + "pointsForTournament": "1", + "places": "1", "roles": document.getElementById("category").value, - "phone": document.getElementById("phone").value, - "director": document.getElementById("director").value, - "phone": document.getElementById("regphone").value, + "ranked": document.getElementById("rank").value, + "place": document.getElementById("place").value, + "from": "string", + "to": "string", + "rang": "rang1", "entryFee": document.getElementById("entry-fee").value, - "additionalInformations": document.getElementById("add-info").value + "director": document.getElementById("director").value, + "phone": document.getElementById("phone").value, + "entriesTo": "string", + "additionalInformations": document.getElementById("add-info").value, + "categotry": "cat1", + "visibility": "TRUE" + + } ) } @@ -55,3 +65,30 @@ function createTournament() { .then(data => console.log(data)) .catch(error => console.log(error)) } + +function logout() { + localStorage.clear(); + location.reload(); +} + +function logoutVisibility() { + if (localStorage.getItem("token") !== null) { + document.getElementById("logout").style.display = ""; + } + else { + document.getElementById("logout").style.display = "none"; + + } + +} + + +function loginVisibility() { + if (localStorage.getItem("token") !== null) { + document.getElementById("login").style.display = "none"; + } + else { + document.getElementById("login").style.display = ""; + + } +} \ No newline at end of file diff --git a/frontend/panel_organizatora/dodawanie turnieju/index.html b/frontend/panel_organizatora/dodawanie turnieju/index.html index d48b34a..b9a3072 100644 --- a/frontend/panel_organizatora/dodawanie turnieju/index.html +++ b/frontend/panel_organizatora/dodawanie turnieju/index.html @@ -9,21 +9,25 @@ - + +
- +
- +
.
.
diff --git a/frontend/panel_organizatora/logowanie/app.js b/frontend/panel_organizatora/logowanie/app.js index 96dfa48..cdfc81f 100644 --- a/frontend/panel_organizatora/logowanie/app.js +++ b/frontend/panel_organizatora/logowanie/app.js @@ -1,4 +1,25 @@ + + +function checkRole() { + fetch('https://dragonmaster.pl/inz/user', { + headers: { + Authorization: ("Bearer " + localStorage.getItem("token")) + } + }) + .then(res => res.json()) + .then(json => { + if (json['role'] == '1') { + window.location.href = '../../index.html' + } + else { + window.location.href = '../dodawanie turnieju/index.html' + } + }) + +} + function login() { + localStorage.clear() fetch('https://dragonmaster.pl/inz/user/login', { method: "POST", headers: { @@ -20,9 +41,11 @@ function login() { return res }) .then(res => res.json()) - .then(data => console.log(data['token']?.length > 0 ? localStorage.setItem("token", data['token']) : alert("Błędne dane!"))) + .then(data => { + console.log(data['token']?.length > 0 ? localStorage.setItem("token", data['token']) : alert("Błędne dane!")) + checkRole(); + }) .catch(error => console.log(error)) - checkRole(); } @@ -51,16 +74,4 @@ function login() { // .then(data => console.log(data['token']?.length > 0 ? localStorage.setItem("token", data['token']) : 'niedziaua')) // .catch(error => console.log(error)) // .then(token1 => token = token1) -// } - -function checkRole() { - - fetch('https://dragonmaster.pl/inz/user', { - headers: { - Authorization: ("Bearer " + localStorage.getItem("token")) - } - }) - .then(res => res.json()) - .then(json => console.log(json['role']?.length == 1 ? window.location.href = '../index.html' : window.location.href = '../dodawanie-turnieju/index.html ')) - -} \ No newline at end of file +// } \ No newline at end of file