function checkRole() { fetch('https://dragonmaster.pl/inz/user', { headers: { Authorization: ("Bearer " + localStorage.getItem("token")) } }) .then(res => res.json()) .then(json => { if (json['role'] == '1') { window.location.href = '../index.html' } else { window.location.href = '../../panel_organizatora/dodawanie turnieju/index.html' } }) } function login() { localStorage.clear() 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 } ) } ) .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!")) checkRole(); }) .catch(error => console.log(error)) } function tournamentSave() { fetch('https://dragonmaster.pl/inz/registration', { method: "PUT", headers: { Authorization: ("Bearer " + localStorage.getItem("token")) }, body: JSON.stringify( { "paymentmethod": "cash", "tournament": localStorage.getItem('tournamentId'), "partner": document.getElementById("ID_input").value } ) } ) .then(res => { if (res.ok) { alert("Udało się zapisać!") window.location.href = '../index.html' } else { console.log("Coś poszło nie tak!") } return res }) .then(res => res.json()) .catch(error => console.log(error)) }