From 54b4b03d897adce4bdff064c9c7960430761b094 Mon Sep 17 00:00:00 2001 From: Arek Date: Mon, 30 May 2022 19:05:46 +0200 Subject: [PATCH] feat: :sparkles: Dodanie Api Dodanie Api i przeniesienie kodu javascriptowego do osobnego pliku API --- frontend/rejestracja/api.js | 148 +++++++++++++++++++++++++++++++ frontend/rejestracja/index.html | 123 ++++++++++++------------- frontend/rejestracja/myscript.js | 72 +++++++++++++++ 3 files changed, 277 insertions(+), 66 deletions(-) create mode 100644 frontend/rejestracja/api.js create mode 100644 frontend/rejestracja/myscript.js diff --git a/frontend/rejestracja/api.js b/frontend/rejestracja/api.js new file mode 100644 index 0000000..7f7f009 --- /dev/null +++ b/frontend/rejestracja/api.js @@ -0,0 +1,148 @@ +var token = ""; +document.getElementById("loginButton").addEventListener("click", function () { + document.getElementById("login").style.display = "block"; +}); + +document.getElementById("regButton").addEventListener("click", function () { + document.getElementById("reg").style.display = "block"; +}); +document.getElementById("registrationButton").addEventListener("click", function () { + document.getElementById("registration").style.display = "block"; +}); +document.getElementById("checkPaymentButton").addEventListener("click", function () { + document.getElementById("checkStatus").style.display = "block"; +}); +var registartions = []; +document.getElementById("getRegistartionsButton").addEventListener("click", function () { + document.getElementById("getRegistartions").style.display = "block"; +}); +document.getElementById("getUserDataButton").addEventListener("click", function () { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState == 4 && this.status == 200) { + var json = JSON.parse(this.response); + document.getElementById("getUserDataid").innerText = json.id; + document.getElementById("getUserDataname").innerText = json.name; + document.getElementById("getUserDatasurname").innerText = json.surname; + document.getElementById("getUserDatarole").innerText = json.role; + document.getElementById("getUserDatalogin").innerText = json.login; + document.getElementById("getUserDataphone").innerText = json.phone; + document.getElementById("getUserDatamail").innerText = json.mail; + document.getElementById("getUserData").style.display = "block"; + } else if (this.readyState == 4) { + alert("something not work :( " + this.status); + } + } + xhttp.open("GET", "/inz/user"); + xhttp.setRequestHeader("Authorization", "Bearer " + token); + xhttp.send(); +}); +document.getElementById("updateUserDataButton").addEventListener("click", function () { + document.getElementById("updateUserData").style.display = "block"; +}); +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", "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 + '"}'); +}); + +document.getElementById("loginsubmit").addEventListener("click", function () { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState == 4 && this.status == 200) { + alert("logged in"); + token = JSON.parse(this.response).token; + document.getElementById("loginarea").style.display = "none"; + document.getElementById("other").style.display = "block"; + } else if (this.readyState == 4) { + alert("something not work :( " + this.status); + } + } + xhttp.open("POST", "/inz/user/login"); + xhttp.send('{"username":"' + document.getElementById("loginusername").value + '","password":"' + document.getElementById("loginpassword").value + '"}'); +}); +document.getElementById("registrationsubmit").addEventListener("click", function () { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState == 4 && this.status == 200) { + document.getElementById("registrationretu").innerText = JSON.parse(this.response).id; + if (document.getElementById("registrationpaymentmethod").value == "btc") { + var splited = JSON.parse(this.response).url.split("/"); + window.btcpay.showInvoice(splited[splited.length - 1]); + + } + } else if (this.readyState == 4) { + alert("something not work :( " + this.status); + } + } + xhttp.open("PUT", "/inz/registration"); + xhttp.setRequestHeader("Authorization", "Bearer " + token); + xhttp.send('{"paymentmethod":"' + document.getElementById("registrationpaymentmethod").value + '","tournament":"' + document.getElementById("registrationtournament").value + '","partner":"' + document.getElementById("registrationpartner").value + '"}'); +}); + +document.getElementById("checkStatussubmit").addEventListener("click", function () { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState == 4 && this.status == 200) { + document.getElementById("checkStatusretu").innerText = JSON.parse(this.response).status; + } else if (this.readyState == 4) { + alert("something not work :( " + this.status); + } + } + xhttp.open("GET", "/inz/registration/paymentstatus?id=" + document.getElementById("checkStatusid").value); + xhttp.setRequestHeader("Authorization", "Bearer " + token); + xhttp.send(); +}); + +document.getElementById("getRegistartionsSubmit").addEventListener("click", function () { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState == 4 && this.status == 200) { + registartions = JSON.parse(this.response); + document.getElementById("getRegistartionsid").innerText = registartions[0].id; + document.getElementById("getRegistartionsuserid").innerText = registartions[0].userid; + document.getElementById("getRegistartionstournamentid").innerText = registartions[0].tournamentid; + document.getElementById("getRegistartionspaymenttype").innerText = registartions[0].paymenttype; + document.getElementById("getRegistartionspaymentstatus").innerText = registartions[0].paymentstatus; + document.getElementById("getRegistartionsapprovals").innerText = registartions[0].approval; + } else if (this.readyState == 4) { + alert("something not work :( " + this.status); + } + } + xhttp.open("GET", "/inz/registrations?id=" + document.getElementById("getRegistartionsiid").value); + xhttp.setRequestHeader("Authorization", "Bearer " + token); + xhttp.send(); + cur = 0; +}); +var cur = 0; +document.getElementById("getRegistartionsNext").addEventListener("click", function () { + cur = cur + 1; + document.getElementById("getRegistartionsid").innerText = registartions[cur].id; + document.getElementById("getRegistartionsuserid").innerText = registartions[cur].userid; + document.getElementById("getRegistartionstournamentid").innerText = registartions[cur].tournamentid; + document.getElementById("getRegistartionspaymenttype").innerText = registartions[cur].paymenttype; + document.getElementById("getRegistartionspaymentstatus").innerText = registartions[cur].paymentstatus; + document.getElementById("getRegistartionsapprovals").innerText = registartions[cur].approval; +}); + +document.getElementById("updatesubmit").addEventListener("click", function () { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState == 4 && this.status == 200) { + alert("200 updated"); + } else if (this.readyState == 4) { + alert("something not work :( " + this.status); + } + } + xhttp.open("POST", "/inz/user"); + xhttp.setRequestHeader("Authorization", "Bearer " + token); + + xhttp.send('{"name":"' + document.getElementById("updatename").value + '","surname":"' + document.getElementById("updatesurname").value + '","password":"' + document.getElementById("updatepassword").value + '","mail":"' + document.getElementById("updatemail").value + '","phone":"' + document.getElementById("updatephone").value + '"}'); +}); \ No newline at end of file diff --git a/frontend/rejestracja/index.html b/frontend/rejestracja/index.html index 7d40069..d9ae8d2 100644 --- a/frontend/rejestracja/index.html +++ b/frontend/rejestracja/index.html @@ -9,86 +9,77 @@ + -
-
-
-

Rejestracja

+
+
+
+

Rejestracja

- - - -
+ + + +
- - - + + + + - -
+ +
- - - - -
+ + + + + +
- - - - -
+ + + + + +
- - - - - -
+ + + + + + +
- - - - - + + + + + + -
-
- -
-
-
- Zapomniałeś hasła? -
- Masz już konto? Zaloguj się +
+
+ +
+
+
+ Zapomniałeś hasła? +
+ Masz już konto? Zaloguj się +
+
- -
- - - + diff --git a/frontend/rejestracja/myscript.js b/frontend/rejestracja/myscript.js new file mode 100644 index 0000000..989a50a --- /dev/null +++ b/frontend/rejestracja/myscript.js @@ -0,0 +1,72 @@ +const togglePassword = document.querySelector("#togglePassword"); +const password = document.querySelector("#regpassword"); + +togglePassword.addEventListener("click", function () { + // toggle the type attribute + const type = password.getAttribute("type") === "password" ? "text" : "password"; + password.setAttribute("type", type); + + // toggle the icon + this.classList.toggle("bi-eye"); +}); + +// prevent form submit +const form = document.querySelector("form"); +form.addEventListener('submit', function (e) { + e.preventDefault(); +}); + +var token = ""; +document.getElementById("loginButton").addEventListener("click", function () { + document.getElementById("login").style.display = "block"; +}); + +document.getElementById("regButton").addEventListener("click", function () { + document.getElementById("reg").style.display = "block"; +}); +document.getElementById("registrationButton").addEventListener("click", function () { + document.getElementById("registration").style.display = "block"; +}); +document.getElementById("checkPaymentButton").addEventListener("click", function () { + document.getElementById("checkStatus").style.display = "block"; +}); +var registartions = []; +document.getElementById("getRegistartionsButton").addEventListener("click", function () { + document.getElementById("getRegistartions").style.display = "block"; +}); +document.getElementById("getUserDataButton").addEventListener("click", function () { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState == 4 && this.status == 200) { + var json = JSON.parse(this.response); + document.getElementById("getUserDataid").innerText = json.id; + document.getElementById("getUserDataname").innerText = json.name; + document.getElementById("getUserDatasurname").innerText = json.surname; + document.getElementById("getUserDatarole").innerText = json.role; + document.getElementById("getUserDatalogin").innerText = json.login; + document.getElementById("getUserDataphone").innerText = json.phone; + document.getElementById("getUserDatamail").innerText = json.mail; + document.getElementById("getUserData").style.display = "block"; + } else if (this.readyState == 4) { + alert("something not work :( " + this.status); + } + } + xhttp.open("GET", "dragonmaster.pl//inz/user"); + xhttp.setRequestHeader("Authorization", "Bearer " + token); + xhttp.send(); +}); +document.getElementById("updateUserDataButton").addEventListener("click", function () { + document.getElementById("updateUserData").style.display = "block"; +}); +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", "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