From d3961bee19be9dea6ca2cb15c4b272a5e363a9b1 Mon Sep 17 00:00:00 2001 From: Arek Date: Fri, 10 Jun 2022 00:56:06 +0200 Subject: [PATCH] feat: :sparkles: Connected with api workign login, registration, tournaments get --- .../dodawanie turnieju/app.js | 84 ++++++++++++------- .../dodawanie turnieju/index.html | 22 ++--- frontend/panel_organizatora/logowanie/app.js | 78 +++++++++++++---- .../panel_organizatora/logowanie/index.html | 5 +- .../panel_organizatora/rejestracja/index.html | 8 +- .../rejestracja/myscript.js | 22 +---- 6 files changed, 139 insertions(+), 80 deletions(-) diff --git a/frontend/panel_organizatora/dodawanie turnieju/app.js b/frontend/panel_organizatora/dodawanie turnieju/app.js index 8b48717..8269ff2 100644 --- a/frontend/panel_organizatora/dodawanie turnieju/app.js +++ b/frontend/panel_organizatora/dodawanie turnieju/app.js @@ -1,29 +1,57 @@ -document.getElementById("tournamentSubmit").addEventListener("click", function () { - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function () { - if (this.readyState == 4 && this.status == 200) { - alert("Dodano turniej"); - } else if (this.readyState == 4) { - alert("something not work :( " + this.status); - } +// document.getElementById("tournamentSubmit").addEventListener("click", function () { +// var xhttp = new XMLHttpRequest(); +// xhttp.onreadystatechange = function () { +// if (this.readyState == 4 && this.status == 200) { +// alert("Dodano turniej"); +// } else if (this.readyState == 4) { +// alert("something not work :( " + this.status); +// } +// } +// xhttp.open("PUT", "dragonmaster.pl/inz/tournament"); +// xhttp.setRequestHeader("Authorization", "Bearer " + token); +// xhttp.send('{"name":"' + document.getElementById("tournamentName").value + +// '","typeOfLadder":"' + document.getElementById("ladderType").value + +// '","pointsForTournament":"' + document.getElementById("tournamentPoints").value + +// '","places":"' + document.getElementById("tournamentPlace").value + +// '","roles":"' + document.getElementById("tournamentRole").value + +// '","ranked":"' + document.getElementById("isRanked").value + +// '","place":"' + document.getElementById("tournamentPlace").value + +// '","from":"' + document.getElementById("tournamentFrom").value + +// '","to":"' + document.getElementById("tournamentTo").value + +// '","rang":"' + document.getElementById("tournamentRang").value + +// '","entyFee":"' + document.getElementById("tournamentEntyFee").value + +// '","director":"' + document.getElementById("tournamentDirector").value + +// '","phone":"' + document.getElementById("directorphone").value + +// '","entriesTo":"' + document.getElementById("tournamentEntriesTo").value + +// '","additionalInformations":"' + document.getElementById("tournamentAddInfo").value + +// '","category":"' + "cat1" + +// '","}'); +// }); + +function createTournament() { + fetch('https://dragonmaster.pl/inz/tournament', { + method: "PUT", + headers: { + 'Content-type': 'application/json', + Authorization: ("Bearer " + localStorage.getItem("token")) + }, + body: JSON.stringify( + { + "name": document.getElementById("name").value, + "place": document.getElementById("place").value, + "ranked": document.getElementById("rank").value, + "roles": document.getElementById("category").value, + "phone": document.getElementById("phone").value, + "director": document.getElementById("director").value, + "phone": document.getElementById("regphone").value, + "entryFee": document.getElementById("entry-fee").value, + "additionalInformations": document.getElementById("add-info").value + } + ) } - xhttp.open("PUT", "dragonmaster.pl/inz/tournament"); - xhttp.setRequestHeader("Authorization", "Bearer " + token); - xhttp.send('{"name":"' + document.getElementById("tournamentName").value + - '","typeOfLadder":"' + document.getElementById("ladderType").value + - '","pointsForTournament":"' + document.getElementById("tournamentPoints").value + - '","places":"' + document.getElementById("tournamentPlace").value + - '","roles":"' + document.getElementById("tournamentRole").value + - '","ranked":"' + document.getElementById("isRanked").value + - '","place":"' + document.getElementById("tournamentPlace").value + - '","from":"' + document.getElementById("tournamentFrom").value + - '","to":"' + document.getElementById("tournamentTo").value + - '","rang":"' + document.getElementById("tournamentRang").value + - '","entyFee":"' + document.getElementById("tournamentEntyFee").value + - '","director":"' + document.getElementById("tournamentDirector").value + - '","phone":"' + document.getElementById("directorphone").value + - '","entriesTo":"' + document.getElementById("tournamentEntriesTo").value + - '","additionalInformations":"' + document.getElementById("tournamentAddInfo").value + - '","category":"' + "cat1" + - '","}'); -}); \ No newline at end of file + ) + + .then(res => res.json()) + .then(data => console.log(data)) + .catch(error => console.log(error)) +} diff --git a/frontend/panel_organizatora/dodawanie turnieju/index.html b/frontend/panel_organizatora/dodawanie turnieju/index.html index 36ed585..d48b34a 100644 --- a/frontend/panel_organizatora/dodawanie turnieju/index.html +++ b/frontend/panel_organizatora/dodawanie turnieju/index.html @@ -31,57 +31,57 @@

Nazwa Turnieju

Termin

Miejsce

Kategorie

Ranga

Wpisowe

Dyrektor Turnieju

Telefon

Zapisy

Dodatkowe informacje


- diff --git a/frontend/panel_organizatora/logowanie/app.js b/frontend/panel_organizatora/logowanie/app.js index 142b61c..96dfa48 100644 --- a/frontend/panel_organizatora/logowanie/app.js +++ b/frontend/panel_organizatora/logowanie/app.js @@ -1,18 +1,66 @@ -document.getElementById("loginsubmit").addEventListener("click", function () { - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function () { - if (this.readyState == 4 && this.status == 200) { - alert("logged in"); - console.log("dziala"); - } else if (this.readyState == 4) { - alert("something not work :( " + this.status); - console.log("nie dziala"); - } +function login() { + fetch('https://dragonmaster.pl/inz/user/login', { + method: "POST", + headers: { + 'Content-type': 'application/json' + }, + body: JSON.stringify( + { + "username": document.getElementById("loginusername").value, + "password": document.getElementById("loginpassword").value + } + ) } - xhttp.open("POST", "https://dragonmaster.pl/inz/user/login"); - xhttp.send('{"username":"' + document.getElementById("loginusername").value + '","password":"' + document.getElementById("loginpassword").value + '"}'); -}); + ) + .then(res => { + if (res.ok) { + // alert("Teraz mozesz się zalogować!") + } + else { console.log("Coś poszło nie tak!") } + return res + }) + .then(res => res.json()) + .then(data => console.log(data['token']?.length > 0 ? localStorage.setItem("token", data['token']) : alert("Błędne dane!"))) + .catch(error => console.log(error)) + checkRole(); +} + + +// function checkRole() { +// fetch('https://dragonmaster.pl/inz/user', { +// method: "GET", +// headers: { +// 'Content-type': 'application/json' +// }, +// body: JSON.stringify( +// { +// "token": document.getElementById("loginusername").value, +// "password": document.getElementById("loginpassword").value +// } +// ) +// } +// ) +// .then(res => { +// if (res.ok) { +// alert("Teraz mozesz się zalogować!") +// } +// else { console.log("Coś poszło nie tak!") } +// return res +// }) +// .then(res => res.json()) +// .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 ')) -function submit() { - ("form").submit(function () { return false; }) } \ No newline at end of file diff --git a/frontend/panel_organizatora/logowanie/index.html b/frontend/panel_organizatora/logowanie/index.html index 053a43a..bf17571 100644 --- a/frontend/panel_organizatora/logowanie/index.html +++ b/frontend/panel_organizatora/logowanie/index.html @@ -20,10 +20,9 @@
- -
Zapomniałeś hasła?
diff --git a/frontend/panel_organizatora/rejestracja/index.html b/frontend/panel_organizatora/rejestracja/index.html index 64ba48e..fa14834 100644 --- a/frontend/panel_organizatora/rejestracja/index.html +++ b/frontend/panel_organizatora/rejestracja/index.html @@ -11,6 +11,7 @@ +
@@ -42,9 +43,10 @@ -
- -
+ +
Zapomniałeś hasła? diff --git a/frontend/panel_organizatora/rejestracja/myscript.js b/frontend/panel_organizatora/rejestracja/myscript.js index 6a4435a..db0cfa1 100644 --- a/frontend/panel_organizatora/rejestracja/myscript.js +++ b/frontend/panel_organizatora/rejestracja/myscript.js @@ -11,28 +11,10 @@ togglePassword.addEventListener("click", function () { this.classList.toggle("bi-eye"); }); -// prevent form submit -const form = document.querySelector("form"); -form.addEventListener('submit', function (e) { - e.preventDefault(); -}); - -document.getElementById("regsubmit").addEventListener("click", function () { - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function () { - if (this.readyState == 4 && this.status == 200) { - alert("200 now you can login"); - } else if (this.readyState == 4) { - alert("something not work :( " + this.status); - } - } - xhttp.open("PUT", "https://dragonmaster.pl/inz/user/create"); - xhttp.send('{"username":"' + document.getElementById("regusername").value + '","name":"' + document.getElementById("regname").value + '","surname":"' + document.getElementById("regsurname").value + '","password":"' + document.getElementById("regpassword").value + '","mail":"' + document.getElementById("regmail").value + '","phone":"' + document.getElementById("regphone").value + '"}'); -}); function register() { fetch('https://dragonmaster.pl/inz/user/create', { - method: "PSOT", + method: "PUT", headers: { 'Content-type': 'application/json' }, @@ -51,7 +33,7 @@ function register() { .then(res => { if (res.ok) { alert("Teraz mozesz się zalogować!") - window.open("../panel_organizatora/logowanie/index.html"); + window.location.href = '../logowanie/index.html' } else { console.log("Coś poszło nie tak!") } return res