From 300c80fcd5db5bfedf22f710d4993b979d8fa109 Mon Sep 17 00:00:00 2001 From: Fluffy Date: Thu, 22 Jun 2023 13:19:00 +0000 Subject: [PATCH] Yeet useless tables Yeet useless data paths in dockerfile Add order into templates file --- TFR/Dockerfile | 1 - TFR/server/__init__.py | 5 +-- TFR/server/api.py | 1 - TFR/server/auth.py | 7 ++- TFR/server/config.py | 3 -- TFR/server/filters.py | 6 +-- TFR/server/models.py | 25 ++--------- TFR/server/templates/auth.html | 43 ------------------- TFR/server/templates/base.html | 33 ++++++-------- TFR/server/templates/macros/input.html | 15 +++++++ TFR/server/templates/navigation.html | 15 +++++++ TFR/server/templates/{ => views}/about.html | 0 TFR/server/templates/views/auth.html | 25 +++++++++++ TFR/server/templates/{ => views}/scores.html | 0 .../templates/{ => views}/settings.html | 0 TFR/server/views.py | 10 +++-- docker-compose.yml | 3 +- 17 files changed, 86 insertions(+), 106 deletions(-) delete mode 100644 TFR/server/templates/auth.html create mode 100644 TFR/server/templates/macros/input.html create mode 100644 TFR/server/templates/navigation.html rename TFR/server/templates/{ => views}/about.html (100%) create mode 100644 TFR/server/templates/views/auth.html rename TFR/server/templates/{ => views}/scores.html (100%) rename TFR/server/templates/{ => views}/settings.html (100%) diff --git a/TFR/Dockerfile b/TFR/Dockerfile index 67491da..130c6aa 100644 --- a/TFR/Dockerfile +++ b/TFR/Dockerfile @@ -2,7 +2,6 @@ FROM alpine:latest EXPOSE 8000 -# RUN apt update && apt install -y python3 python3-pip postgresql-client RUN apk update && apk add python3 py3-pip postgresql-client WORKDIR /data diff --git a/TFR/server/__init__.py b/TFR/server/__init__.py index 077f7e4..e910a85 100644 --- a/TFR/server/__init__.py +++ b/TFR/server/__init__.py @@ -4,17 +4,16 @@ from flask import Flask, render_template, abort from flask_assets import Bundle from werkzeug.exceptions import HTTPException -from .config import MIGRATION_DIR, INSTANCE_DIR from .extensions import db, migrate, cache, assets, login_manager from .models import Users from . import views, auth, api, filters -app = Flask(__name__, instance_path=INSTANCE_DIR) +app = Flask(__name__) app.config.from_pyfile("config.py") db.init_app(app) -migrate.init_app(app, db, directory=MIGRATION_DIR) +migrate.init_app(app, db) with app.app_context(): db.create_all() diff --git a/TFR/server/api.py b/TFR/server/api.py index b873962..1513d4a 100644 --- a/TFR/server/api.py +++ b/TFR/server/api.py @@ -59,7 +59,6 @@ def post(): if int(difficulty) not in GAME_DIFFICULTIES: return "Invalid difficulty!" - session_data = Sessions.query.filter_by(auth_key=session_key).first() if not session_data: return "Authentication failed!" diff --git a/TFR/server/auth.py b/TFR/server/auth.py index 607d126..272e5ff 100644 --- a/TFR/server/auth.py +++ b/TFR/server/auth.py @@ -15,7 +15,7 @@ blueprint = Blueprint("auth", __name__) @blueprint.route("/auth", methods=["GET"]) def auth(): - return render_template("auth.html") + return render_template("views/auth.html") @blueprint.route("/register", methods=["POST"]) @@ -59,10 +59,9 @@ def register(): @blueprint.route("/login", methods=["POST"]) def login(): # Get the form data - username = request.form["username"].strip() - password = request.form["password"].strip() + username = request.form.get("username", None).strip() + password = request.form.get("password", None).strip() username_regex = re.compile(USER_REGEX) - error = [] # Validate the form diff --git a/TFR/server/config.py b/TFR/server/config.py index 9a6a266..b612d79 100644 --- a/TFR/server/config.py +++ b/TFR/server/config.py @@ -23,9 +23,6 @@ SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{user}:{password}@{host}:5432/ SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_POOL_RECYCLE = 621 -MIGRATION_DIR = "/data/storage/migrations" -INSTANCE_DIR = "/data/storage/instance" - """ # SQLite SECRET_KEY = "dev" diff --git a/TFR/server/filters.py b/TFR/server/filters.py index 213c535..ed4a030 100644 --- a/TFR/server/filters.py +++ b/TFR/server/filters.py @@ -2,12 +2,12 @@ import datetime from flask import Blueprint -blueprint = Blueprint('filters', __name__, template_folder='templates') +blueprint = Blueprint("filters", __name__, template_folder="templates") @blueprint.app_template_filter() def format_result(dttm): - dttm = str(dttm).split('.') + dttm = str(dttm).split(".") time = datetime.timedelta(seconds=int(dttm[0])) microtime = dttm[1][:3] - return f'{time}:{microtime}' + return f"{time}:{microtime}" diff --git a/TFR/server/models.py b/TFR/server/models.py index 2c15299..70b6551 100644 --- a/TFR/server/models.py +++ b/TFR/server/models.py @@ -9,9 +9,6 @@ from .config import GAME_VERSION class Scores(db.Model): """ Post table - Scores supports anonymous posting, and instead just wants to post a score, - then the username must be provided. Otherwise, it's grabbed from the user - table """ id = db.Column(db.Integer, primary_key=True) @@ -75,25 +72,6 @@ class PasswordReset(db.Model): ) -class Permissions(db.Model): - """ - Permissions table - """ - - id = db.Column(db.Integer, primary_key=True) - user_id = db.Column(db.Integer, db.ForeignKey("users.id", use_alter=True)) - - user_ban = db.Column(db.Boolean, default=False) - user_warn = db.Column(db.Boolean, default=False) - - score_removal = db.Column(db.Boolean, default=False) - score_edit = db.Column(db.Boolean, default=False) - - admin_panel = db.Column(db.Boolean, default=False) - admin_promote = db.Column(db.Boolean, default=False) - admin_demote = db.Column(db.Boolean, default=False) - - class ProfileTags(db.Model): """ Profile Tags table @@ -112,6 +90,9 @@ class Users(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) alt_id = db.Column(db.String, nullable=False, unique=True) + superuser = db.Column(db.Boolean, default=False) + + picture = db.Column(db.String) username = db.Column(db.String(32), unique=True, nullable=False) email = db.Column(db.String) diff --git a/TFR/server/templates/auth.html b/TFR/server/templates/auth.html deleted file mode 100644 index e18379a..0000000 --- a/TFR/server/templates/auth.html +++ /dev/null @@ -1,43 +0,0 @@ -{% extends "base.html" %} -{% block content %} -
-

Login

-

Welcome back!

-
- - - - - - - - - - - -
-
- -
-

Register

-

Don't have an account?

-
- - - - - - - - - - - - - - - - -
-
-{% endblock %} \ No newline at end of file diff --git a/TFR/server/templates/base.html b/TFR/server/templates/base.html index 79d0be4..bc2ac5d 100644 --- a/TFR/server/templates/base.html +++ b/TFR/server/templates/base.html @@ -1,7 +1,7 @@ - Front Rooms Highscores + {% block title %}Front Rooms Highscores{% endblock %} @@ -16,10 +16,9 @@ {% assets "scripts" %}{% endassets %} -
-

Start typing to see results...

-
+

Start typing to see results...

+ The Front Rooms Level select render @@ -28,38 +27,30 @@
+ {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} {% for category, message in messages %} -

{{ message }}

+

+ + {{ message }} +

{% endfor %} {% endif %} {% endwith %}
+ The Front Rooms logo - - - + {% block nav %}{% endblock %}
diff --git a/TFR/server/templates/macros/input.html b/TFR/server/templates/macros/input.html new file mode 100644 index 0000000..f8a7e80 --- /dev/null +++ b/TFR/server/templates/macros/input.html @@ -0,0 +1,15 @@ +{% macro text(id, name, type="text", required=False, minlength=0) %} + + + + + +{% endmacro %} \ No newline at end of file diff --git a/TFR/server/templates/navigation.html b/TFR/server/templates/navigation.html new file mode 100644 index 0000000..f2401ec --- /dev/null +++ b/TFR/server/templates/navigation.html @@ -0,0 +1,15 @@ + diff --git a/TFR/server/templates/about.html b/TFR/server/templates/views/about.html similarity index 100% rename from TFR/server/templates/about.html rename to TFR/server/templates/views/about.html diff --git a/TFR/server/templates/views/auth.html b/TFR/server/templates/views/auth.html new file mode 100644 index 0000000..b5fdf5a --- /dev/null +++ b/TFR/server/templates/views/auth.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} +{% from "macros/input.html" import text %} + +{% block content %} +
+

Login

+

Welcome back!

+
+ {{ text(id="login-username", name="username", required=True) }} + {{ text(id="login-password", name="password", type="password", required=True) }} + +
+
+ +
+

Register

+

Don't have an account?

+
+ {{ text(id="register-username", name="username", required=True) }} + {{ text(id="register-password", name="password", type="password", required=True, minlength=8) }} + {{ text(id="register-confirm", name="confirm", type="password", required=True, minlength=8) }} + +
+
+{% endblock %} \ No newline at end of file diff --git a/TFR/server/templates/scores.html b/TFR/server/templates/views/scores.html similarity index 100% rename from TFR/server/templates/scores.html rename to TFR/server/templates/views/scores.html diff --git a/TFR/server/templates/settings.html b/TFR/server/templates/views/settings.html similarity index 100% rename from TFR/server/templates/settings.html rename to TFR/server/templates/views/settings.html diff --git a/TFR/server/views.py b/TFR/server/views.py index 3cdc99c..80e428d 100644 --- a/TFR/server/views.py +++ b/TFR/server/views.py @@ -27,13 +27,17 @@ def index(): scores = scores.order_by(Scores.score.asc()).limit(MAX_TOP_SCORES).all() return render_template( - "scores.html", scores=scores, diff=int(diff_arg), ver=ver_arg, user=user_arg + "views/scores.html", + scores=scores, + diff=int(diff_arg), + ver=ver_arg, + user=user_arg ) @blueprint.route("/about") def about(): - return render_template("about.html") + return render_template("views/about.html") @blueprint.route("/settings", methods=["GET"]) @@ -51,4 +55,4 @@ def settings(): flash("Insert password change function", "error") sessions = Sessions.query.filter_by(user_id=current_user.id).all() - return render_template("settings.html", sessions=sessions) + return render_template("views/settings.html", sessions=sessions) diff --git a/docker-compose.yml b/docker-compose.yml index bad0391..7de16b7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,8 +36,7 @@ services: build: TFR restart: unless-stopped volumes: - - ./TFR/storage:/data/storage - - ./TFR/logs:/data/logs + - ./TFR/storage/migrations:/data/migrations environment: FLASK_KEY: ${THE_FRONT_ROOMS_SECRETE_KEY} DB_USER: ${POSTGRES_USER}