added user registration and login

This commit is contained in:
2025-01-20 15:42:10 +02:00
parent a6d0bbbd2b
commit 850360f553
16 changed files with 500 additions and 17 deletions

68
templates/admin.html Normal file
View File

@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html>
<head>
<title>Admin Panel</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container py-5">
<h1 class="text-center mb-4">Admin Panel</h1>
<h2>Manage Users</h2>
<table class="table">
<thead>
<tr>
<th>Username</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{ user.username }}</td>
<td>{{ user.role }}</td>
<td>
<form action="{{ url_for('change_role', user_id=user.id) }}" method="post" class="d-inline">
<select name="role" class="form-select d-inline-block" style="width: auto;">
<option value="user" {% if user.role == 'user' %}selected{% endif %}>User</option>
<option value="admin" {% if user.role == 'admin' %}selected{% endif %}>Admin</option>
</select>
<button type="submit" class="btn btn-sm btn-primary">Change Role</button>
</form>
<form action="{{ url_for('delete_user', user_id=user.id) }}" method="post" class="d-inline">
<button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this user?');">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<h2>Create New User</h2>
<form action="{{ url_for('create_user') }}" method="post">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role" required>
<option value="user">User</option>
<option value="admin">Admin</option>
</select>
</div>
<button type="submit" class="btn btn-success">Create User</button>
</form>
<div class="mt-4">
<a href="{{ url_for('dashboard') }}" class="btn btn-secondary">Back to Dashboard</a>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@@ -10,6 +10,23 @@
<div class="container py-5">
<h1 class="text-center mb-4">Dashboard</h1>
<!-- Sign Out Button -->
<div class="text-end mb-4">
<a href="{{ url_for('logout') }}" class="btn btn-danger">Sign Out</a>
</div>
<!-- Users Management Section -->
{% if current_user.role == 'admin' %}
<div class="card mb-4">
<div class="card-header bg-info text-white">
<h2>Users Management</h2>
</div>
<div class="card-body text-center">
<a href="{{ url_for('admin') }}" class="btn btn-info btn-lg">Manage Users</a>
</div>
</div>
{% endif %}
<!-- Players Section -->
<div class="card mb-4">
<div class="card-header bg-primary text-white">
@@ -18,8 +35,6 @@
<div class="card-body">
<ul class="list-group">
{% for player in players %}
<!-- ...existing code... -->
<li class="list-group-item d-flex justify-content-between align-items-center">
<div>
<strong>{{ player.username }}</strong> ({{ player.ip }})
@@ -27,18 +42,20 @@
<div>
<a href="{{ url_for('player_page', player_id=player.id) }}" class="btn btn-sm btn-secondary">View Schedule</a>
<a href="{{ url_for('player_fullscreen', player_id=player.id) }}" class="btn btn-sm btn-primary">Full Screen</a>
{% if current_user.role == 'admin' %}
<form action="{{ url_for('delete_player', player_id=player.id) }}" method="post" style="display:inline;">
<button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this player?');">Delete</button>
</form>
{% endif %}
</div>
</li>
<!-- ...existing code... -->
{% endfor %}
</ul>
{% if current_user.role == 'admin' %}
<div class="mt-3">
<a href="{{ url_for('add_player') }}" class="btn btn-success">Add Player</a>
</div>
{% endif %}
</div>
</div>
@@ -55,9 +72,11 @@
</li>
{% endfor %}
</ul>
{% if current_user.role == 'admin' %}
<div class="mt-3">
<a href="{{ url_for('add_group') }}" class="btn btn-primary">Add Group</a>
</div>
{% endif %}
</div>
</div>

24
templates/login.html Normal file
View File

@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container py-5">
<h1 class="text-center mb-4">Login</h1>
<form action="{{ url_for('login') }}" method="post">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

24
templates/register.html Normal file
View File

@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container py-5">
<h1 class="text-center mb-4">Register</h1>
<form action="{{ url_for('register') }}" method="post">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>