feat: ✨ Connected with api
workign login, registration, tournaments get
This commit is contained in:
parent
2cbd9c29d7
commit
d3961bee19
@ -1,29 +1,57 @@
|
|||||||
document.getElementById("tournamentSubmit").addEventListener("click", function () {
|
// document.getElementById("tournamentSubmit").addEventListener("click", function () {
|
||||||
var xhttp = new XMLHttpRequest();
|
// var xhttp = new XMLHttpRequest();
|
||||||
xhttp.onreadystatechange = function () {
|
// xhttp.onreadystatechange = function () {
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
// if (this.readyState == 4 && this.status == 200) {
|
||||||
alert("Dodano turniej");
|
// alert("Dodano turniej");
|
||||||
} else if (this.readyState == 4) {
|
// } else if (this.readyState == 4) {
|
||||||
alert("something not work :( " + this.status);
|
// alert("something not work :( " + this.status);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
// xhttp.open("PUT", "dragonmaster.pl/inz/tournament");
|
||||||
|
// xhttp.setRequestHeader("Authorization", "Bearer " + token);
|
||||||
|
// xhttp.send('{"name":"' + document.getElementById("tournamentName").value +
|
||||||
|
// '","typeOfLadder":"' + document.getElementById("ladderType").value +
|
||||||
|
// '","pointsForTournament":"' + document.getElementById("tournamentPoints").value +
|
||||||
|
// '","places":"' + document.getElementById("tournamentPlace").value +
|
||||||
|
// '","roles":"' + document.getElementById("tournamentRole").value +
|
||||||
|
// '","ranked":"' + document.getElementById("isRanked").value +
|
||||||
|
// '","place":"' + document.getElementById("tournamentPlace").value +
|
||||||
|
// '","from":"' + document.getElementById("tournamentFrom").value +
|
||||||
|
// '","to":"' + document.getElementById("tournamentTo").value +
|
||||||
|
// '","rang":"' + document.getElementById("tournamentRang").value +
|
||||||
|
// '","entyFee":"' + document.getElementById("tournamentEntyFee").value +
|
||||||
|
// '","director":"' + document.getElementById("tournamentDirector").value +
|
||||||
|
// '","phone":"' + document.getElementById("directorphone").value +
|
||||||
|
// '","entriesTo":"' + document.getElementById("tournamentEntriesTo").value +
|
||||||
|
// '","additionalInformations":"' + document.getElementById("tournamentAddInfo").value +
|
||||||
|
// '","category":"' + "cat1" +
|
||||||
|
// '","}');
|
||||||
|
// });
|
||||||
|
|
||||||
|
function createTournament() {
|
||||||
|
fetch('https://dragonmaster.pl/inz/tournament', {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
'Content-type': 'application/json',
|
||||||
|
Authorization: ("Bearer " + localStorage.getItem("token"))
|
||||||
|
},
|
||||||
|
body: JSON.stringify(
|
||||||
|
{
|
||||||
|
"name": document.getElementById("name").value,
|
||||||
|
"place": document.getElementById("place").value,
|
||||||
|
"ranked": document.getElementById("rank").value,
|
||||||
|
"roles": document.getElementById("category").value,
|
||||||
|
"phone": document.getElementById("phone").value,
|
||||||
|
"director": document.getElementById("director").value,
|
||||||
|
"phone": document.getElementById("regphone").value,
|
||||||
|
"entryFee": document.getElementById("entry-fee").value,
|
||||||
|
"additionalInformations": document.getElementById("add-info").value
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
xhttp.open("PUT", "dragonmaster.pl/inz/tournament");
|
)
|
||||||
xhttp.setRequestHeader("Authorization", "Bearer " + token);
|
|
||||||
xhttp.send('{"name":"' + document.getElementById("tournamentName").value +
|
.then(res => res.json())
|
||||||
'","typeOfLadder":"' + document.getElementById("ladderType").value +
|
.then(data => console.log(data))
|
||||||
'","pointsForTournament":"' + document.getElementById("tournamentPoints").value +
|
.catch(error => console.log(error))
|
||||||
'","places":"' + document.getElementById("tournamentPlace").value +
|
}
|
||||||
'","roles":"' + document.getElementById("tournamentRole").value +
|
|
||||||
'","ranked":"' + document.getElementById("isRanked").value +
|
|
||||||
'","place":"' + document.getElementById("tournamentPlace").value +
|
|
||||||
'","from":"' + document.getElementById("tournamentFrom").value +
|
|
||||||
'","to":"' + document.getElementById("tournamentTo").value +
|
|
||||||
'","rang":"' + document.getElementById("tournamentRang").value +
|
|
||||||
'","entyFee":"' + document.getElementById("tournamentEntyFee").value +
|
|
||||||
'","director":"' + document.getElementById("tournamentDirector").value +
|
|
||||||
'","phone":"' + document.getElementById("directorphone").value +
|
|
||||||
'","entriesTo":"' + document.getElementById("tournamentEntriesTo").value +
|
|
||||||
'","additionalInformations":"' + document.getElementById("tournamentAddInfo").value +
|
|
||||||
'","category":"' + "cat1" +
|
|
||||||
'","}');
|
|
||||||
});
|
|
||||||
|
@ -31,57 +31,57 @@
|
|||||||
<div class="form">
|
<div class="form">
|
||||||
<h3 class="descriptor">Nazwa Turnieju</h3>
|
<h3 class="descriptor">Nazwa Turnieju</h3>
|
||||||
<label>
|
<label>
|
||||||
<input>
|
<input id="name">
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<h3 class="descriptor">Termin</h3>
|
<h3 class="descriptor">Termin</h3>
|
||||||
<label>
|
<label>
|
||||||
<input>
|
<input id="term">
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<h3 class="descriptor">Miejsce</h3>
|
<h3 class="descriptor">Miejsce</h3>
|
||||||
<label>
|
<label>
|
||||||
<input>
|
<input id="place">
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<h3 class="descriptor">Kategorie</h3>
|
<h3 class="descriptor">Kategorie</h3>
|
||||||
<label>
|
<label>
|
||||||
<input>
|
<input id="category">
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<h3 class="descriptor">Ranga</h3>
|
<h3 class="descriptor">Ranga</h3>
|
||||||
<label>
|
<label>
|
||||||
<input>
|
<input id="rank">
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<h3 class="descriptor">Wpisowe</h3>
|
<h3 class="descriptor">Wpisowe</h3>
|
||||||
<label>
|
<label>
|
||||||
<input>
|
<input id="entry-fee">
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<h3 class="descriptor">Dyrektor Turnieju</h3>
|
<h3 class="descriptor">Dyrektor Turnieju</h3>
|
||||||
<label>
|
<label>
|
||||||
<input>
|
<input id="director">
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<h3 class="descriptor">Telefon</h3>
|
<h3 class="descriptor">Telefon</h3>
|
||||||
<label>
|
<label>
|
||||||
<input>
|
<input id="phone">
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<h3 class="descriptor">Zapisy</h3>
|
<h3 class="descriptor">Zapisy</h3>
|
||||||
<label>
|
<label>
|
||||||
<input>
|
<input id="entries">
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<h3 class="descriptor">Dodatkowe informacje</h3>
|
<h3 class="descriptor">Dodatkowe informacje</h3>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<textarea name="Text1" cols="40" rows="5"></textarea>
|
<textarea name="Text1" cols="40" rows="5" id="add-info"></textarea>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
<button class="myButton" type="submit" id="tournamentsubmit">
|
<button class="myButton" type="submit" id="tournamentsubmit" onclick="createTournament()">
|
||||||
Załóż turniej
|
Załóż turniej
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@ -1,18 +1,66 @@
|
|||||||
document.getElementById("loginsubmit").addEventListener("click", function () {
|
function login() {
|
||||||
var xhttp = new XMLHttpRequest();
|
fetch('https://dragonmaster.pl/inz/user/login', {
|
||||||
xhttp.onreadystatechange = function () {
|
method: "POST",
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
headers: {
|
||||||
alert("logged in");
|
'Content-type': 'application/json'
|
||||||
console.log("dziala");
|
},
|
||||||
} else if (this.readyState == 4) {
|
body: JSON.stringify(
|
||||||
alert("something not work :( " + this.status);
|
{
|
||||||
console.log("nie dziala");
|
"username": document.getElementById("loginusername").value,
|
||||||
}
|
"password": document.getElementById("loginpassword").value
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
xhttp.open("POST", "https://dragonmaster.pl/inz/user/login");
|
)
|
||||||
xhttp.send('{"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!")))
|
||||||
|
.catch(error => console.log(error))
|
||||||
|
checkRole();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
// }
|
||||||
|
|
||||||
|
function checkRole() {
|
||||||
|
|
||||||
|
fetch('https://dragonmaster.pl/inz/user', {
|
||||||
|
headers: {
|
||||||
|
Authorization: ("Bearer " + localStorage.getItem("token"))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(json => console.log(json['role']?.length == 1 ? window.location.href = '../index.html' : window.location.href = '../dodawanie-turnieju/index.html '))
|
||||||
|
|
||||||
function submit() {
|
|
||||||
("form").submit(function () { return false; })
|
|
||||||
}
|
}
|
@ -20,10 +20,9 @@
|
|||||||
<br>
|
<br>
|
||||||
|
|
||||||
<!-- trzeba dać cssy buttonowi bo zmieniłem z form na button -->
|
<!-- trzeba dać cssy buttonowi bo zmieniłem z form na button -->
|
||||||
<button>
|
<button class="myButton" id="loginsubmit" onclick="login()">
|
||||||
<input class="myButton" type="submit" value="Zaloguj" id="loginsubmit" />
|
Zaloguj
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<a href="#">Zapomniałeś hasła?</a>
|
<a href="#">Zapomniałeś hasła?</a>
|
||||||
<br>
|
<br>
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="form">
|
<div class="form">
|
||||||
<div class="register">
|
<div class="register">
|
||||||
@ -42,9 +43,10 @@
|
|||||||
<input placeholder="Potwierdź hasło" type="password" id="password2" name="password">
|
<input placeholder="Potwierdź hasło" type="password" id="password2" name="password">
|
||||||
<i class="bi bi-eye-slash" id="togglePassword2"></i>
|
<i class="bi bi-eye-slash" id="togglePassword2"></i>
|
||||||
|
|
||||||
<form action="reg" onclick="register()">
|
|
||||||
<input class="myButton" type="submit" value="Zarejestruj" id="regsubmit" />
|
<button class="myButton" id="regsubmit" onclick="register()">
|
||||||
</form>
|
Zajerestruj
|
||||||
|
</button>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<a href="#">Zapomniałeś hasła?</a>
|
<a href="#">Zapomniałeś hasła?</a>
|
||||||
|
@ -11,28 +11,10 @@ togglePassword.addEventListener("click", function () {
|
|||||||
this.classList.toggle("bi-eye");
|
this.classList.toggle("bi-eye");
|
||||||
});
|
});
|
||||||
|
|
||||||
// prevent form submit
|
|
||||||
const form = document.querySelector("form");
|
|
||||||
form.addEventListener('submit', function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
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", "https://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 + '"}');
|
|
||||||
});
|
|
||||||
|
|
||||||
function register() {
|
function register() {
|
||||||
fetch('https://dragonmaster.pl/inz/user/create', {
|
fetch('https://dragonmaster.pl/inz/user/create', {
|
||||||
method: "PSOT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-type': 'application/json'
|
'Content-type': 'application/json'
|
||||||
},
|
},
|
||||||
@ -51,7 +33,7 @@ function register() {
|
|||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
alert("Teraz mozesz się zalogować!")
|
alert("Teraz mozesz się zalogować!")
|
||||||
window.open("../panel_organizatora/logowanie/index.html");
|
window.location.href = '../logowanie/index.html'
|
||||||
}
|
}
|
||||||
else { console.log("Coś poszło nie tak!") }
|
else { console.log("Coś poszło nie tak!") }
|
||||||
return res
|
return res
|
||||||
|
Loading…
Reference in New Issue
Block a user