2022-06-15 15:43:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-18 14:35:43 +02:00
|
|
|
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ć!")
|
2022-06-19 13:14:20 +02:00
|
|
|
window.location.href = '../index.html'
|
2022-06-18 14:35:43 +02:00
|
|
|
}
|
|
|
|
else { console.log("Coś poszło nie tak!") }
|
|
|
|
return res
|
|
|
|
})
|
|
|
|
.then(res => res.json())
|
|
|
|
.catch(error => console.log(error))
|
|
|
|
}
|
|
|
|
|
|
|
|
|