diff --git a/app.py b/app.py index 398ee1a..a7b489c 100644 --- a/app.py +++ b/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/', 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//edit', methods=['GET', 'POST']) +@app.route('/edit_player/', 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: diff --git a/instance/dashboard.db b/instance/dashboard.db index bb53da3..2bc3538 100644 Binary files a/instance/dashboard.db and b/instance/dashboard.db differ diff --git a/static/uploads/login_picture.png b/static/uploads/login_picture.png new file mode 100644 index 0000000..b8bfa51 Binary files /dev/null and b/static/uploads/login_picture.png differ diff --git a/static/uploads/logo.png b/static/uploads/logo.png new file mode 100644 index 0000000..aeb8795 Binary files /dev/null and b/static/uploads/logo.png differ diff --git a/static/uploads/start_page.jpeg b/static/uploads/start_page.jpeg new file mode 100644 index 0000000..3a57493 Binary files /dev/null and b/static/uploads/start_page.jpeg differ diff --git a/templates/admin.html b/templates/admin.html index 6de9995..da3d4a6 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -15,6 +15,10 @@ .dark-mode label, .dark-mode th, .dark-mode td { color: #ffffff; } + .img-preview { + max-width: 100px; + max-height: 100px; + } @@ -25,57 +29,98 @@

Manage Users

- -

Manage User Roles

- - - - - - - - - - {% for user in users %} - - - - - - {% endfor %} - -
UsernameRoleActions
{{ user.username }}{{ user.role }} -
- - -
-
- -
-
+
+
+

Manage User Roles

+ + + + + + + + + + {% for user in users %} + + + + + + {% endfor %} + +
UsernameRoleActions
{{ user.username }}{{ user.role }} +
+ + +
+
+ +
+
+
+
+
+
+
+

Add User

+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+ - -

Add New User

-
-
- - +
+
+

Upload Personalization Photos for the App

+
+
+ +
+
+ + {% if logo_exists %} + Current Logo + {% endif %} +
+
+ + +
-
- - +
+
+ + {% if login_picture_exists %} + Current Login Picture + {% endif %} +
+
+ + +
-
- - -
- +
diff --git a/templates/dashboard.html b/templates/dashboard.html index 8d9e5e6..b95ac26 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -14,11 +14,20 @@ background-color: #1e1e1e; color: #ffffff; } + .logo { + max-height: 100px; + margin-right: 20px; + }
-

Dashboard

+
+ {% if logo_exists %} + + {% endif %} +

Dashboard

+
diff --git a/templates/edit_player.html b/templates/edit_player.html index 897982b..4b90c7a 100644 --- a/templates/edit_player.html +++ b/templates/edit_player.html @@ -3,30 +3,40 @@ Edit Player + - +

Edit Player

- +
- -
-
- - +
- +
- Back to Player Page + Back to Player Page + Back to Dashboard
diff --git a/templates/login.html b/templates/login.html index c11439b..9f0debe 100644 --- a/templates/login.html +++ b/templates/login.html @@ -3,21 +3,37 @@ Login +
-

Login

-
-
- - +
+
+ {% if login_picture_exists %} + + {% endif %}
-
- - +
+

Login

+ +
+ + +
+
+ + +
+ +
- - +
diff --git a/templates/player_page.html b/templates/player_page.html index 47efaf2..b8ec0dd 100644 --- a/templates/player_page.html +++ b/templates/player_page.html @@ -29,9 +29,8 @@

Player Name: {{ player.username }}

Hostname: {{ player.hostname }}

-

IP Address: {{ player.ip }}

{% if current_user.role == 'admin' %} - Update + Update
@@ -63,14 +62,16 @@ {% if content %}
    {% for media in content %} -
  • -

    Media Name: {{ media.file_name }}

    -

    Duration: {{ media.duration }} minutes

    -
    -
    - - +
  • +
    +

    Media Name: {{ media.file_name }}

    +
    + +
    + seconds +
    +