updated the manage player pages
This commit is contained in:
60
app.py
60
app.py
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
from flask import Flask, render_template, request, redirect, url_for, session
|
||||
from flask import Flask, render_template, request, redirect, url_for, session, flash
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_login import LoginManager, UserMixin, login_user, logout_user, login_required, current_user
|
||||
from flask_bcrypt import Bcrypt
|
||||
@@ -80,6 +80,12 @@ def dashboard():
|
||||
groups = Group.query.all()
|
||||
return render_template('dashboard.html', players=players, groups=groups)
|
||||
|
||||
@app.route('/dashboard')
|
||||
@login_required
|
||||
def dashboard():
|
||||
logo_exists = os.path.exists(os.path.join(app.config['UPLOAD_FOLDER'], 'logo.png'))
|
||||
return render_template('dashboard.html', logo_exists=logo_exists)
|
||||
|
||||
@app.route('/register', methods=['GET', 'POST'])
|
||||
def register():
|
||||
if request.method == 'POST':
|
||||
@@ -101,7 +107,11 @@ def login():
|
||||
if user and bcrypt.check_password_hash(user.password, password):
|
||||
login_user(user)
|
||||
return redirect(url_for('dashboard'))
|
||||
return render_template('login.html')
|
||||
else:
|
||||
flash('Login Unsuccessful. Please check username and password', 'danger')
|
||||
|
||||
login_picture_exists = os.path.exists(os.path.join(app.config['UPLOAD_FOLDER'], 'login_picture.png'))
|
||||
return render_template('login.html', login_picture_exists=login_picture_exists)
|
||||
|
||||
@app.route('/logout')
|
||||
@login_required
|
||||
@@ -144,8 +154,10 @@ def upload_content():
|
||||
@login_required
|
||||
@admin_required
|
||||
def admin():
|
||||
logo_exists = os.path.exists(os.path.join(app.config['UPLOAD_FOLDER'], 'logo.png'))
|
||||
login_picture_exists = os.path.exists(os.path.join(app.config['UPLOAD_FOLDER'], 'login_picture.png'))
|
||||
users = User.query.all()
|
||||
return render_template('admin.html', users=users)
|
||||
return render_template('admin.html', users=users, logo_exists=logo_exists, login_picture_exists=login_picture_exists)
|
||||
|
||||
@app.route('/admin/change_role/<int:user_id>', methods=['POST'])
|
||||
@login_required
|
||||
@@ -373,7 +385,7 @@ def integrate_player():
|
||||
groups = Group.query.all()
|
||||
return render_template('integrate_player.html', players=players, groups=groups)
|
||||
|
||||
@app.route('/player/<int:player_id>/edit', methods=['GET', 'POST'])
|
||||
@app.route('/edit_player/<int:player_id>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@admin_required
|
||||
def edit_player(player_id):
|
||||
@@ -385,7 +397,9 @@ def edit_player(player_id):
|
||||
player.password = bcrypt.generate_password_hash(request.form['password']).decode('utf-8')
|
||||
db.session.commit()
|
||||
return redirect(url_for('player_page', player_id=player.id))
|
||||
return render_template('edit_player.html', player=player)
|
||||
|
||||
return_url = request.args.get('return_url', url_for('player_page', player_id=player.id))
|
||||
return render_template('edit_player.html', player=player, return_url=return_url)
|
||||
|
||||
@app.route('/change_theme', methods=['POST'])
|
||||
@login_required
|
||||
@@ -396,6 +410,42 @@ def change_theme():
|
||||
db.session.commit()
|
||||
return redirect(url_for('admin'))
|
||||
|
||||
@app.route('/upload_logo', methods=['POST'])
|
||||
@login_required
|
||||
@admin_required
|
||||
def upload_logo():
|
||||
if 'logo' not in request.files:
|
||||
return redirect(url_for('admin'))
|
||||
|
||||
file = request.files['logo']
|
||||
if file.filename == '':
|
||||
return redirect(url_for('admin'))
|
||||
|
||||
if file:
|
||||
filename = secure_filename(file.filename)
|
||||
file_path = os.path.join(app.config['UPLOAD_FOLDER'], 'logo.png')
|
||||
file.save(file_path)
|
||||
return redirect(url_for('admin'))
|
||||
|
||||
@app.route('/upload_personalization_pictures', methods=['POST'])
|
||||
@login_required
|
||||
@admin_required
|
||||
def upload_personalization_pictures():
|
||||
logo_file = request.files.get('logo')
|
||||
login_picture_file = request.files.get('login_picture')
|
||||
|
||||
if logo_file and logo_file.filename != '':
|
||||
logo_filename = secure_filename(logo_file.filename)
|
||||
logo_file_path = os.path.join(app.config['UPLOAD_FOLDER'], 'logo.png')
|
||||
logo_file.save(logo_file_path)
|
||||
|
||||
if login_picture_file and login_picture_file.filename != '':
|
||||
login_picture_filename = secure_filename(login_picture_file.filename)
|
||||
login_picture_file_path = os.path.join(app.config['UPLOAD_FOLDER'], 'login_picture.png')
|
||||
login_picture_file.save(login_picture_file_path)
|
||||
|
||||
return redirect(url_for('admin'))
|
||||
|
||||
@app.context_processor
|
||||
def inject_theme():
|
||||
if current_user.is_authenticated:
|
||||
|
||||
Binary file not shown.
BIN
static/uploads/login_picture.png
Normal file
BIN
static/uploads/login_picture.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 153 KiB |
BIN
static/uploads/logo.png
Normal file
BIN
static/uploads/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
BIN
static/uploads/start_page.jpeg
Normal file
BIN
static/uploads/start_page.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 737 KiB |
@@ -15,6 +15,10 @@
|
||||
.dark-mode label, .dark-mode th, .dark-mode td {
|
||||
color: #ffffff;
|
||||
}
|
||||
.img-preview {
|
||||
max-width: 100px;
|
||||
max-height: 100px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="{{ 'dark-mode' if theme == 'dark' else '' }}">
|
||||
@@ -25,57 +29,98 @@
|
||||
<h2>Manage Users</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<!-- Manage User Roles Section -->
|
||||
<h3>Manage User Roles</h3>
|
||||
<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>
|
||||
<div class="row">
|
||||
<div class="col-md-5">
|
||||
<h3>Manage User Roles</h3>
|
||||
<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>
|
||||
</div>
|
||||
<div class="col-md-1 d-flex justify-content-center">
|
||||
<div class="vr"></div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h3>Add User</h3>
|
||||
<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 {{ 'dark-mode' if theme == 'dark' else '' }}" id="username" name="username" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control {{ 'dark-mode' if theme == 'dark' else '' }}" id="password" name="password" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="role" class="form-label">Role</label>
|
||||
<select class="form-select {{ 'dark-mode' if theme == 'dark' else '' }}" id="role" name="role" required>
|
||||
<option value="admin">Admin</option>
|
||||
<option value="user">User</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Add User</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add New User Section -->
|
||||
<h3 class="mt-4">Add New User</h3>
|
||||
<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 class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
||||
<div class="card-header">
|
||||
<h2>Upload Personalization Photos for the App</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{ url_for('upload_personalization_pictures') }}" method="post" enctype="multipart/form-data">
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-4">
|
||||
<label for="logo" class="form-label">Current Logo</label>
|
||||
{% if logo_exists %}
|
||||
<img src="{{ url_for('static', filename='uploads/logo.png') }}" alt="Current Logo" class="img-thumbnail img-preview mb-3">
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<label for="logo" class="form-label">Select New Logo</label>
|
||||
<input type="file" class="form-control {{ 'dark-mode' if theme == 'dark' else '' }}" id="logo" name="logo">
|
||||
</div>
|
||||
</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 class="row mb-3">
|
||||
<div class="col-md-4">
|
||||
<label for="login_picture" class="form-label">Current Login Page Picture</label>
|
||||
{% if login_picture_exists %}
|
||||
<img src="{{ url_for('static', filename='uploads/login_picture.png') }}" alt="Current Login Picture" class="img-thumbnail img-preview mb-3">
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<label for="login_picture" class="form-label">Select New Login Page Picture</label>
|
||||
<input type="file" class="form-control {{ 'dark-mode' if theme == 'dark' else '' }}" id="login_picture" name="login_picture">
|
||||
</div>
|
||||
</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>
|
||||
<button type="submit" class="btn btn-primary">Upload Pictures</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -14,11 +14,20 @@
|
||||
background-color: #1e1e1e;
|
||||
color: #ffffff;
|
||||
}
|
||||
.logo {
|
||||
max-height: 100px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="{{ 'dark-mode' if theme == 'dark' else '' }}">
|
||||
<div class="container py-5">
|
||||
<h1 class="text-center mb-4">Dashboard</h1>
|
||||
<div class="d-flex justify-content-start align-items-center mb-4">
|
||||
{% if logo_exists %}
|
||||
<img src="{{ url_for('static', filename='uploads/logo.png') }}" alt="Logo" class="logo">
|
||||
{% endif %}
|
||||
<h1 class="mb-0">Dashboard</h1>
|
||||
</div>
|
||||
|
||||
<!-- Sign Out Button -->
|
||||
<div class="text-end mb-4">
|
||||
|
||||
@@ -3,30 +3,40 @@
|
||||
<head>
|
||||
<title>Edit Player</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body.dark-mode {
|
||||
background-color: #121212;
|
||||
color: #ffffff;
|
||||
}
|
||||
.card.dark-mode {
|
||||
background-color: #1e1e1e;
|
||||
color: #ffffff;
|
||||
}
|
||||
.dark-mode label, .dark-mode th, .dark-mode td {
|
||||
color: #ffffff;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<body class="{% if theme == 'dark' %}dark-mode{% endif %}">
|
||||
<div class="container py-5">
|
||||
<h1 class="text-center mb-4">Edit Player</h1>
|
||||
<form action="{{ url_for('edit_player', player_id=player.id) }}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Player Name</label>
|
||||
<input type="text" class="form-control" id="username" name="username" value="{{ player.username }}" required>
|
||||
<input type="text" class="form-control {% if theme == 'dark' %}dark-mode{% endif %}" id="username" name="username" value="{{ player.username }}" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="hostname" class="form-label">Hostname</label>
|
||||
<input type="text" class="form-control" id="hostname" name="hostname" value="{{ player.hostname }}" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="ip" class="form-label">IP Address</label>
|
||||
<input type="text" class="form-control" id="ip" name="ip" value="{{ player.ip }}" required>
|
||||
<input type="text" class="form-control {% if theme == 'dark' %}dark-mode{% endif %}" id="hostname" name="hostname" value="{{ player.hostname }}" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password (leave blank to keep current password)</label>
|
||||
<input type="password" class="form-control" id="password" name="password">
|
||||
<input type="password" class="form-control {% if theme == 'dark' %}dark-mode{% endif %}" id="password" name="password">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Update Player</button>
|
||||
</form>
|
||||
<a href="{{ url_for('player_page', player_id=player.id) }}" class="btn btn-secondary mt-3">Back to Player Page</a>
|
||||
<a href="{{ return_url }}" class="btn btn-secondary mt-3">Back to Player Page</a>
|
||||
<a href="{{ url_for('dashboard') }}" class="btn btn-secondary mt-3">Back to Dashboard</a>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -3,21 +3,37 @@
|
||||
<head>
|
||||
<title>Login</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
.login-picture {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
</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 class="row">
|
||||
<div class="col-md-6 text-center">
|
||||
{% if login_picture_exists %}
|
||||
<img src="{{ url_for('static', filename='uploads/login_picture.png') }}" alt="Login Picture" class="login-picture">
|
||||
{% endif %}
|
||||
</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 class="col-md-6">
|
||||
<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 w-100">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -29,9 +29,8 @@
|
||||
<div class="card-body">
|
||||
<p><strong>Player Name:</strong> {{ player.username }}</p>
|
||||
<p><strong>Hostname:</strong> {{ player.hostname }}</p>
|
||||
<p><strong>IP Address:</strong> {{ player.ip }}</p>
|
||||
{% if current_user.role == 'admin' %}
|
||||
<a href="{{ url_for('edit_player', player_id=player.id) }}" class="btn btn-warning">Update</a>
|
||||
<a href="{{ url_for('edit_player', player_id=player.id, return_url=url_for('player_page', player_id=player.id)) }}" class="btn btn-warning">Update</a>
|
||||
<form action="{{ url_for('delete_player', player_id=player.id) }}" method="post" style="display:inline;">
|
||||
<button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this player?');">Delete</button>
|
||||
</form>
|
||||
@@ -63,14 +62,16 @@
|
||||
{% if content %}
|
||||
<ul class="list-group">
|
||||
{% for media in content %}
|
||||
<li class="list-group-item {% if theme == 'dark' %}dark-mode{% endif %}">
|
||||
<p><strong>Media Name:</strong> {{ media.file_name }}</p>
|
||||
<p><strong>Duration:</strong> {{ media.duration }} minutes</p>
|
||||
<form action="{{ url_for('edit_content', content_id=media.id) }}" method="post" style="display:inline;">
|
||||
<div class="input-group mb-3">
|
||||
<input type="number" class="form-control" name="duration" value="{{ media.duration }}" required>
|
||||
<button type="submit" class="btn btn-warning">Edit</button>
|
||||
<li class="list-group-item d-flex align-items-center {% if theme == 'dark' %}dark-mode{% endif %}">
|
||||
<div class="flex-grow-1">
|
||||
<p class="mb-0"><strong>Media Name:</strong> {{ media.file_name }}</p>
|
||||
</div>
|
||||
<form action="{{ url_for('edit_content', content_id=media.id) }}" method="post" class="d-flex align-items-center">
|
||||
<div class="input-group me-2">
|
||||
<span class="input-group-text">seconds</span>
|
||||
<input type="number" class="form-control {% if theme == 'dark' %}dark-mode{% endif %}" name="duration" value="{{ media.duration }}" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-warning me-2">Edit</button>
|
||||
</form>
|
||||
<form action="{{ url_for('delete_content', content_id=media.id) }}" method="post" style="display:inline;">
|
||||
<button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this media?');">Delete</button>
|
||||
|
||||
Reference in New Issue
Block a user