From 2cbd9c29d766e73d71cd55752e6089df5a1945f4 Mon Sep 17 00:00:00 2001 From: Arek Date: Thu, 9 Jun 2022 01:54:13 +0200 Subject: [PATCH] refactor: --- .../panel_organizatora/rejestracja/index.html | 8 +-- .../rejestracja/myscript.js | 33 ++++++++++- frontend/sandbox_api/logowanie.json | 8 +++ frontend/sandbox_api/myscript.js | 57 +++++++++++-------- 4 files changed, 76 insertions(+), 30 deletions(-) create mode 100644 frontend/sandbox_api/logowanie.json diff --git a/frontend/panel_organizatora/rejestracja/index.html b/frontend/panel_organizatora/rejestracja/index.html index 66c619e..64ba48e 100644 --- a/frontend/panel_organizatora/rejestracja/index.html +++ b/frontend/panel_organizatora/rejestracja/index.html @@ -28,21 +28,21 @@
- +
- +
- + -
+
diff --git a/frontend/panel_organizatora/rejestracja/myscript.js b/frontend/panel_organizatora/rejestracja/myscript.js index 24855e7..6a4435a 100644 --- a/frontend/panel_organizatora/rejestracja/myscript.js +++ b/frontend/panel_organizatora/rejestracja/myscript.js @@ -28,4 +28,35 @@ document.getElementById("regsubmit").addEventListener("click", function () { } 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 + '"}'); -}); \ No newline at end of file +}); + +function register() { + fetch('https://dragonmaster.pl/inz/user/create', { + method: "PSOT", + headers: { + 'Content-type': 'application/json' + }, + body: JSON.stringify( + { + "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 + } + ) + } + ) + .then(res => { + if (res.ok) { + alert("Teraz mozesz się zalogować!") + window.open("../panel_organizatora/logowanie/index.html"); + } + else { console.log("Coś poszło nie tak!") } + return res + }) + .then(res => res.json()) + .then(data => console.log(data)) + .catch(error => console.log(error)) +} \ No newline at end of file diff --git a/frontend/sandbox_api/logowanie.json b/frontend/sandbox_api/logowanie.json new file mode 100644 index 0000000..7b66e85 --- /dev/null +++ b/frontend/sandbox_api/logowanie.json @@ -0,0 +1,8 @@ +{ + "username": "string", + "name": "string", + "surname": "string", + "password": "string", + "mail": "string", + "phone": "string" + } \ No newline at end of file diff --git a/frontend/sandbox_api/myscript.js b/frontend/sandbox_api/myscript.js index e380d25..79a45a2 100644 --- a/frontend/sandbox_api/myscript.js +++ b/frontend/sandbox_api/myscript.js @@ -32,31 +32,6 @@ // console.error(error); // }); -// fetch(url) -// .then(response => response.json()) -// .then((data) => { -// let tournaments = data; - -// tournaments.map(function (tournament) { -// let li = document.createElement('li'); -// let name = document.createElement('h2'); -// let email = document.createElement('span'); - -// name.innerHTML = '${tournament.name}'; -// id.innerHTML = '${tournament.id}'; - -// li.appendChild(name); -// li.appendChild(id); -// }); -// }) -// .catch(function (error) { -// console.log(error); -// }); - -// ul.appendChild(list); - -// console.log(fetch('https://dragonmaster.pl/inz/tournaments')) - async function showTournaments() { let url = 'https://dragonmaster.pl/inz/tournaments'; @@ -78,4 +53,36 @@ async function renderTournaments() { let container = document.querySelector('.tournament-list'); container.innerHTML = html; +} + + +function register() { + fetch('https://dragonmaster.pl/inz/user/create', { + method: "PUT", + headers: { + 'Content-type': 'application/json' + }, + body: JSON.stringify( + { + "username": "jaro", + "name": "maro", + "surname": "siaro", + "password": "jaro", + "mail": "jaro@wp.pl", + "phone": "1234567" + } + ) + } + ) + .then(res => { + if (res.ok) { + alert("Teraz mozesz się zalogować!") + window.open("../panel_organizatora/logowanie/index.html"); + } + else { console.log("Coś poszło nie tak!") } + return res + }) + .then(res => res.json()) + .then(data => console.log(data)) + .catch(error => console.log(error)) } \ No newline at end of file