2022-06-10 12:23:44 +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 = '../dodawanie turnieju/index.html'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-10 00:56:06 +02:00
|
|
|
function login() {
|
2022-06-10 12:23:44 +02:00
|
|
|
localStorage.clear()
|
2022-06-10 00:56:06 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
)
|
2022-06-01 22:23:12 +02:00
|
|
|
}
|
2022-06-10 00:56:06 +02:00
|
|
|
)
|
|
|
|
.then(res => {
|
|
|
|
if (res.ok) {
|
|
|
|
// alert("Teraz mozesz się zalogować!")
|
|
|
|
}
|
|
|
|
else { console.log("Coś poszło nie tak!") }
|
|
|
|
return res
|
|
|
|
})
|
|
|
|
.then(res => res.json())
|
2022-06-10 12:23:44 +02:00
|
|
|
.then(data => {
|
|
|
|
console.log(data['token']?.length > 0 ? localStorage.setItem("token", data['token']) : alert("Błędne dane!"))
|
|
|
|
checkRole();
|
|
|
|
})
|
2022-06-10 00:56:06 +02:00
|
|
|
.catch(error => console.log(error))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// function checkRole() {
|
|
|
|
// fetch('https://dragonmaster.pl/inz/user', {
|
|
|
|
// method: "GET",
|
|
|
|
// headers: {
|
|
|
|
// 'Content-type': 'application/json'
|
|
|
|
// },
|
|
|
|
// body: JSON.stringify(
|
|
|
|
// {
|
|
|
|
// "token": 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']) : 'niedziaua'))
|
|
|
|
// .catch(error => console.log(error))
|
|
|
|
// .then(token1 => token = token1)
|
2022-06-10 12:23:44 +02:00
|
|
|
// }
|