-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Undergraduate Student
committed
Dec 15, 2024
1 parent
ecd9f17
commit 501dedf
Showing
6 changed files
with
222 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const API_URL = "https://users.iee.ihu.gr/~iee2020202/ADISE24_DreamTeam/blokus.php/users/"; | ||
|
||
// Handle login | ||
$("#loginForm").on("submit", function (event) { | ||
event.preventDefault(); | ||
|
||
const userId = $("#userId").val(); | ||
|
||
$.ajax({ | ||
url: API_URL + userId, | ||
method: "GET", | ||
success: function (response) { | ||
if (response && response.id) { | ||
// Save user info in sessionStorage | ||
sessionStorage.setItem("loggedInUser", JSON.stringify(response)); | ||
window.location.href = "stats.html"; // Redirect to stats page | ||
} else { | ||
$("#errorMessage").text("Invalid User ID").show(); | ||
} | ||
}, | ||
error: function () { | ||
$("#errorMessage").text("Unable to fetch user data. Please try again.").show(); | ||
}, | ||
}); | ||
}); | ||
|
||
// Redirect to login if not logged in | ||
if (window.location.pathname.endsWith("stats.html")) { | ||
const loggedInUser = sessionStorage.getItem("loggedInUser"); | ||
if (!loggedInUser) { | ||
window.location.href = "login.html"; | ||
} else { | ||
const user = JSON.parse(loggedInUser); | ||
$("#userId").text(user.id); | ||
$("#username").text(user.username); | ||
$("#email").text(user.email); | ||
$("#createdAt").text(user.created_at); | ||
} | ||
} | ||
|
||
// Logout functionality | ||
$("#logoutBtn").on("click", function () { | ||
sessionStorage.removeItem("loggedInUser"); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Login Page</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> | ||
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="row justify-content-center mt-5"> | ||
<div class="col-md-4"> | ||
<div class="card"> | ||
<div class="card-header text-center"> | ||
<h4>Login</h4> | ||
</div> | ||
<div class="card-body"> | ||
<form id="loginForm"> | ||
<div class="form-group mb-3"> | ||
<label for="userId">User ID</label> | ||
<input type="number" id="userId" class="form-control" placeholder="Enter your User ID" required> | ||
</div> | ||
<button type="submit" class="btn btn-primary w-100">Login</button> | ||
</form> | ||
<div id="errorMessage" class="text-danger mt-3" style="display: none;"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script src="app.js"></script> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>User Stats</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> | ||
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="row justify-content-center mt-5"> | ||
<div class="col-md-6"> | ||
<div class="card"> | ||
<div class="card-header text-center"> | ||
<h4>Your Stats</h4> | ||
</div> | ||
<div class="card-body"> | ||
<p><strong>Username:</strong> <span id="usernameDisplay"></span></p> | ||
<p><strong>Total Games Played:</strong> <span id="totalGames"></span></p> | ||
<p><strong>Wins:</strong> <span id="wins"></span></p> | ||
<p><strong>Losses:</strong> <span id="losses"></span></p> | ||
<a href="login.html" id="logoutBtn" class="btn btn-danger w-100">Logout</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script src="app.js"></script> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>User Stats</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> | ||
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="row justify-content-center mt-5"> | ||
<div class="col-md-6"> | ||
<div class="card"> | ||
<div class="card-header text-center"> | ||
<h4>Your Stats</h4> | ||
</div> | ||
<div class="card-body"> | ||
<p><strong>ID:</strong> <span id="userId"></span></p> | ||
<p><strong>Username:</strong> <span id="username"></span></p> | ||
<p><strong>Email:</strong> <span id="email"></span></p> | ||
<p><strong>Created At:</strong> <span id="createdAt"></span></p> | ||
<a href="login.html" id="logoutBtn" class="btn btn-danger w-100">Logout</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script src="app.js"></script> | ||
</body> | ||
</html> | ||
|