From 060956fe996eb414ae275713e838423fa5f5ed95 Mon Sep 17 00:00:00 2001 From: Ske087 Date: Wed, 22 Jan 2025 11:29:29 +0200 Subject: [PATCH] finised app --- app.py | 54 ++++++++++++++++++---- instance/dashboard.db | Bin 49152 -> 49152 bytes templates/add_player.html | 2 +- templates/dashboard.html | 14 +++++- templates/edit_player.html | 33 +++++++++++++ templates/integrate_player.html | 79 ++++++++++++++++++++++++++++++++ templates/player_auth.html | 24 ++++++++++ templates/player_page.html | 18 ++++++++ 8 files changed, 213 insertions(+), 11 deletions(-) create mode 100644 templates/edit_player.html create mode 100644 templates/integrate_player.html create mode 100644 templates/player_auth.html diff --git a/app.py b/app.py index 742b348..7c64a35 100644 --- a/app.py +++ b/app.py @@ -281,18 +281,31 @@ def delete_content(content_id): db.session.commit() return redirect(url_for('player_page', player_id=player_id)) -@app.route('/player//fullscreen') -@login_required +@app.route('/player//fullscreen', methods=['GET', 'POST']) def player_fullscreen(player_id): player = Player.query.get_or_404(player_id) - if player.groups: - # If the player is part of a group, get the group's content - group = player.groups[0] # Assuming a player can only be in one group - content = Content.query.filter_by(group_id=group.id).all() + + if request.method == 'POST': + hostname = request.form['hostname'] + password = request.form['password'] + if player.hostname == hostname and bcrypt.check_password_hash(player.password, password): + authenticated = True + else: + authenticated = False else: - # If the player is not part of a group, get the player's content - content = Content.query.filter_by(player_id=player_id).all() - return render_template('player_fullscreen.html', player=player, content=content) + authenticated = False + + if authenticated or current_user.is_authenticated: + if player.groups: + # If the player is part of a group, get the group's content + group = player.groups[0] # Assuming a player can only be in one group + content = Content.query.filter_by(group_id=group.id).all() + else: + # If the player is not part of a group, get the player's content + content = Content.query.filter_by(player_id=player_id).all() + return render_template('player_fullscreen.html', player=player, content=content) + else: + return render_template('player_auth.html', player_id=player_id) @app.route('/group//fullscreen') @login_required @@ -338,6 +351,29 @@ def add_group(): return redirect(url_for('dashboard')) return render_template('add_group.html') +@app.route('/integrate_player') +@login_required +@admin_required +def integrate_player(): + players = Player.query.all() + groups = Group.query.all() + return render_template('integrate_player.html', players=players, groups=groups) + +@app.route('/player//edit', methods=['GET', 'POST']) +@login_required +@admin_required +def edit_player(player_id): + player = Player.query.get_or_404(player_id) + if request.method == 'POST': + player.username = request.form['username'] + player.hostname = request.form['hostname'] + player.ip = request.form['ip'] + if request.form['password']: + 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) + if __name__ == '__main__': with app.app_context(): db.create_all() # Creează toate tabelele diff --git a/instance/dashboard.db b/instance/dashboard.db index 9dec58c252e5d6d5ed890417f08785281ffd6a7f..9c5bd0d49e7527b04dd6a6b0859f5dbc3e1cc93f 100644 GIT binary patch delta 110 zcmZo@U~Xt&o*>PrHc`fzQEg+wvh{4y4E)FVqcVGIKD<>Z&)gPM)@3%|^v2 zNyX4e#iQKZqsqw1%se|FxzsB+C9OO%BvG#@(<3D*BqOja!qmtpQ{N>oGcYK?A~Di4 O-_)SQBy;ky{Z;_?79uSG delta 59 zcmZo@U~Xt&o*>PrI#I@%QFUX&vh{3z4E)FV`!*}`H}P|rF|#ws>Z&VFPT8-<<(ZdR Pl9`xeV5m6x*nTSj4ABxS diff --git a/templates/add_player.html b/templates/add_player.html index a0f8c21..85f3e96 100644 --- a/templates/add_player.html +++ b/templates/add_player.html @@ -9,7 +9,7 @@

Add Player

- +
diff --git a/templates/dashboard.html b/templates/dashboard.html index 30c5f4d..03bc970 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -40,7 +40,7 @@ {{ player.username }} ({{ player.ip }})
- View Schedule + Manage Player Full Screen {% if current_user.role == 'admin' %} @@ -102,6 +102,18 @@ Upload Content
+ + + {% if current_user.role == 'admin' %} +
+
+

Integrate Player

+
+ +
+ {% endif %} diff --git a/templates/edit_player.html b/templates/edit_player.html new file mode 100644 index 0000000..897982b --- /dev/null +++ b/templates/edit_player.html @@ -0,0 +1,33 @@ + + + + Edit Player + + + +
+

Edit Player

+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + + Back to Player Page +
+ + + \ No newline at end of file diff --git a/templates/integrate_player.html b/templates/integrate_player.html new file mode 100644 index 0000000..b84871a --- /dev/null +++ b/templates/integrate_player.html @@ -0,0 +1,79 @@ + + + + Integrate Player + + + +
+

Integrate Player

+ + +
+
+

Players

+
+
+
+ {% for player in players %} +
+
+
+
{{ player.username }}
+

{{ player.ip }}

+
+ + +
+ Fullscreen Link +
+
+
+ {% endfor %} +
+
+
+ + +
+
+

Groups

+
+
+
+ {% for group in groups %} +
+
+
+
{{ group.name }}
+

{{ group.players | length }} players

+
+ + +
+ Fullscreen Link +
+
+
+ {% endfor %} +
+
+
+ + Back to Dashboard +
+ + + + \ No newline at end of file diff --git a/templates/player_auth.html b/templates/player_auth.html new file mode 100644 index 0000000..2ff29e6 --- /dev/null +++ b/templates/player_auth.html @@ -0,0 +1,24 @@ + + + + Player Authentication + + + +
+

Player Authentication

+
+
+ + +
+
+ + +
+ +
+
+ + + \ No newline at end of file diff --git a/templates/player_page.html b/templates/player_page.html index 6788db9..ddbf382 100644 --- a/templates/player_page.html +++ b/templates/player_page.html @@ -8,6 +8,24 @@

Player Schedule for {{ player.username }}

+ +
+
+

Player Info

+
+
+

Player Name: {{ player.username }}

+

Hostname: {{ player.hostname }}

+

IP Address: {{ player.ip }}

+ {% if current_user.role == 'admin' %} + Update +
+ +
+ {% endif %} +
+
+
{% if player.groups %}