feat: ✨ logout button
now you can easy logout
This commit is contained in:
parent
d3961bee19
commit
cf2b59b751
@ -11,15 +11,16 @@ async function showTournaments() {
|
|||||||
async function renderTournaments() {
|
async function renderTournaments() {
|
||||||
let tournaments = await showTournaments();
|
let tournaments = await showTournaments();
|
||||||
let html = '';
|
let html = '';
|
||||||
|
console.log(tournaments)
|
||||||
tournaments.forEach(tournament => {
|
tournaments.forEach(tournament => {
|
||||||
let htmlSegment = `<div class = "tournamentBox">
|
let htmlSegment = `<div class = "tournamentBox" onclick="window.location.href='_main page/pojedynczy_turniej/index.html';loca">
|
||||||
<div class="tournamentIconBox">
|
<div class="tournamentIconBox">
|
||||||
<img class="tournamentIcon" src="_main%20page/cup.svg" alt="">
|
<img class="tournamentIcon" src="_main%20page/cup.svg" alt="">
|
||||||
</div>
|
</div>
|
||||||
<div class="tournamentDataBox">
|
<div class="tournamentDataBox">
|
||||||
<div class="tournamentData">
|
<div class="tournamentData">
|
||||||
<h4>${tournament.name}</h4>
|
<h4>${tournament.name}</h4>
|
||||||
Propadel, Warszawa
|
${tournament.place}
|
||||||
${tournament.from} do ${tournament.to}
|
${tournament.from} do ${tournament.to}
|
||||||
<button class="tournamentOpen">OPEN</button>
|
<button class="tournamentOpen">OPEN</button>
|
||||||
</div>
|
</div>
|
||||||
@ -32,3 +33,30 @@ async function renderTournaments() {
|
|||||||
let container = document.querySelector('.tournament-list');
|
let container = document.querySelector('.tournament-list');
|
||||||
container.innerHTML = html;
|
container.innerHTML = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logout() {
|
||||||
|
localStorage.clear();
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
function logoutVisibility() {
|
||||||
|
if (localStorage.getItem("token") !== null) {
|
||||||
|
document.getElementById("logout").style.display = "";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById("logout").style.display = "none";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loginVisibility() {
|
||||||
|
if (localStorage.getItem("token") !== null) {
|
||||||
|
document.getElementById("login").style.display = "none";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById("login").style.display = "";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,7 @@
|
|||||||
<script type="text/javascript" src="app.js"></script>
|
<script type="text/javascript" src="app.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload="renderTournaments()">
|
<body onload="renderTournaments();logoutVisibility(); loginVisibility()">
|
||||||
<header>
|
<header>
|
||||||
<div class="logoBox">
|
<div class="logoBox">
|
||||||
<a class="header_link" href="./index.html"><img class="logo" src="./_global/logo.svg" alt="Logo error"></a>
|
<a class="header_link" href="./index.html"><img class="logo" src="./_global/logo.svg" alt="Logo error"></a>
|
||||||
@ -18,10 +18,11 @@
|
|||||||
<div class="linkBox">
|
<div class="linkBox">
|
||||||
<!-- <span class="dot">JM</span>-->
|
<!-- <span class="dot">JM</span>-->
|
||||||
<button class="loginButton" type="submit"
|
<button class="loginButton" type="submit"
|
||||||
onclick="window.location.href='panel_organizatora/logowanie/index.html'">LOGOWANIE</button>
|
onclick="window.location.href='panel_organizatora/logowanie/index.html'" id="login">LOGOWANIE</button>
|
||||||
<a class="header_link" href="./kontakt/index.html">Kontakt</a>
|
<a class="header_link" href="./kontakt/index.html">Kontakt</a>
|
||||||
<a class="header_link" href="./ranking/index.html">Ranking</a>
|
<a class="header_link" href="./ranking/index.html">Ranking</a>
|
||||||
<a class="header_link" href="./index.html">Kalendarz turniejów</a>
|
<a class="header_link" href="./index.html">Kalendarz turniejów</a>
|
||||||
|
<button class="loginButton" id="logout" onclick="logout()">Wyloguj</button>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
@ -38,14 +38,24 @@ function createTournament() {
|
|||||||
body: JSON.stringify(
|
body: JSON.stringify(
|
||||||
{
|
{
|
||||||
"name": document.getElementById("name").value,
|
"name": document.getElementById("name").value,
|
||||||
"place": document.getElementById("place").value,
|
"typeOfLadder": "string",
|
||||||
"ranked": document.getElementById("rank").value,
|
"pointsForTournament": "1",
|
||||||
|
"places": "1",
|
||||||
"roles": document.getElementById("category").value,
|
"roles": document.getElementById("category").value,
|
||||||
"phone": document.getElementById("phone").value,
|
"ranked": document.getElementById("rank").value,
|
||||||
"director": document.getElementById("director").value,
|
"place": document.getElementById("place").value,
|
||||||
"phone": document.getElementById("regphone").value,
|
"from": "string",
|
||||||
|
"to": "string",
|
||||||
|
"rang": "rang1",
|
||||||
"entryFee": document.getElementById("entry-fee").value,
|
"entryFee": document.getElementById("entry-fee").value,
|
||||||
"additionalInformations": document.getElementById("add-info").value
|
"director": document.getElementById("director").value,
|
||||||
|
"phone": document.getElementById("phone").value,
|
||||||
|
"entriesTo": "string",
|
||||||
|
"additionalInformations": document.getElementById("add-info").value,
|
||||||
|
"categotry": "cat1",
|
||||||
|
"visibility": "TRUE"
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -55,3 +65,30 @@ function createTournament() {
|
|||||||
.then(data => console.log(data))
|
.then(data => console.log(data))
|
||||||
.catch(error => console.log(error))
|
.catch(error => console.log(error))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logout() {
|
||||||
|
localStorage.clear();
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
function logoutVisibility() {
|
||||||
|
if (localStorage.getItem("token") !== null) {
|
||||||
|
document.getElementById("logout").style.display = "";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById("logout").style.display = "none";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loginVisibility() {
|
||||||
|
if (localStorage.getItem("token") !== null) {
|
||||||
|
document.getElementById("login").style.display = "none";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById("login").style.display = "";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -9,21 +9,25 @@
|
|||||||
<link href="style.css" rel="stylesheet">
|
<link href="style.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body onload="logoutVisibility(); loginVisibility()">
|
||||||
|
<script type="text/javascript" src="app.js"></script>
|
||||||
<header>
|
<header>
|
||||||
<div class="logoBox">
|
<div class="logoBox">
|
||||||
<a class="header_link" href="../../index.html"><img class="logo" src="../../_global/logo.svg" alt="Logo error"></a>
|
<a class="header_link" href="../../index.html"><img class="logo" src="../../_global/logo.svg"
|
||||||
|
alt="Logo error"></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="linkBox">
|
<div class="linkBox">
|
||||||
<!-- <span class="dot">JM</span>-->
|
<!-- <span class="dot">JM</span>-->
|
||||||
<button class="loginButton" type="submit" onclick="window.location.href='../logowanie/index.html'">LOGOWANIE</button>
|
<button class="loginButton" type="submit" onclick="window.location.href='../logowanie/index.html'"
|
||||||
|
id="login">LOGOWANIE</button>
|
||||||
<a class="header_link" href="../../kontakt/index.html">Kontakt</a>
|
<a class="header_link" href="../../kontakt/index.html">Kontakt</a>
|
||||||
<a class="header_link" href="../../ranking/index.html">Ranking</a>
|
<a class="header_link" href="../../ranking/index.html">Ranking</a>
|
||||||
<a class="header_link" href="../../index.html">Kalendarz turniejów</a>
|
<a class="header_link" href="../../index.html">Kalendarz turniejów</a>
|
||||||
|
<button id="logout" onclick="logout()">Wyloguj</button>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- TODO sztuczny padding-->
|
<!-- TODO sztuczny padding-->
|
||||||
<div> .</div>
|
<div> .</div>
|
||||||
<div> .</div>
|
<div> .</div>
|
||||||
|
|
||||||
|
@ -1,4 +1,25 @@
|
|||||||
|
|
||||||
|
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function login() {
|
function login() {
|
||||||
|
localStorage.clear()
|
||||||
fetch('https://dragonmaster.pl/inz/user/login', {
|
fetch('https://dragonmaster.pl/inz/user/login', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@ -20,9 +41,11 @@ function login() {
|
|||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => console.log(data['token']?.length > 0 ? localStorage.setItem("token", data['token']) : alert("Błędne dane!")))
|
.then(data => {
|
||||||
.catch(error => console.log(error))
|
console.log(data['token']?.length > 0 ? localStorage.setItem("token", data['token']) : alert("Błędne dane!"))
|
||||||
checkRole();
|
checkRole();
|
||||||
|
})
|
||||||
|
.catch(error => console.log(error))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -52,15 +75,3 @@ function login() {
|
|||||||
// .catch(error => console.log(error))
|
// .catch(error => console.log(error))
|
||||||
// .then(token1 => token = token1)
|
// .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 '))
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user