Padel-Tournaments-System/frontend/rejestracja/myscript.js
Arek 54b4b03d89 feat: Dodanie Api
Dodanie Api i przeniesienie kodu javascriptowego do osobnego pliku

API
2022-05-30 19:05:46 +02:00

72 lines
3.4 KiB
JavaScript

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 + '"}');
});