54b4b03d89
Dodanie Api i przeniesienie kodu javascriptowego do osobnego pliku API
148 lines
7.4 KiB
JavaScript
148 lines
7.4 KiB
JavaScript
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 + '"}');
|
|
}); |