diff --git a/TFR/server/account.py b/TFR/server/account.py index 29e889a..4c647b4 100644 --- a/TFR/server/account.py +++ b/TFR/server/account.py @@ -1,5 +1,4 @@ import uuid -import re import os from PIL import Image @@ -29,9 +28,6 @@ def settings(): username = request.form.get("username", "").strip() email = request.form.get("email", "").strip() password = request.form.get("password", "").strip() - - user_regex = re.compile(USER_REGEX) - email_regex = re.compile(USER_EMAIL_REGEX) error = [] user = Users.query.filter_by(username=current_user.username).first() @@ -78,12 +74,12 @@ def settings(): image.close() if username: - if user_regex.match(username): + if USER_REGEX.match(username): user.username = username else: error.append("Username is invalid!") if email: - if email_regex.match(email): + if USER_EMAIL_REGEX.match(email): user.email = email else: error.append("Email is invalid!") diff --git a/TFR/server/api.py b/TFR/server/api.py index e7e9188..8bcd790 100644 --- a/TFR/server/api.py +++ b/TFR/server/api.py @@ -1,4 +1,3 @@ -import re import shortuuid from flask import Blueprint, request, jsonify, send_from_directory @@ -9,6 +8,9 @@ from werkzeug.utils import secure_filename from .models import Scores, Sessions, Users from .extensions import db from .config import ( + GAME_VERSION, + GAME_VERSIONS, + GAME_DIFFICULTY, GAME_DIFFICULTIES, MAX_SEARCH_RESULTS, USER_REGEX, @@ -49,8 +51,8 @@ def tokens(): @blueprint.route("/post", methods=["POST"]) def post(): session_key = request.form.get("session", "").strip() - version = request.form.get("version", "alpha").strip() - difficulty = request.form.get("difficulty", 0) + version = request.form.get("version", GAME_VERSION).strip() + difficulty = request.form.get("difficulty", GAME_DIFFICULTY) score = request.form.get("score", 0) if not session_key: @@ -66,6 +68,8 @@ def post(): if int(difficulty) not in GAME_DIFFICULTIES: return "Invalid difficulty!" + if version not in GAME_VERSIONS: + return "Invalid version!" # This is a fix for a bug in the game that we dunno how to actually fix # if score < 10: # return "Score is impossible!" @@ -110,9 +114,8 @@ def login(): username = request.form.get("username", "").strip() password = request.form.get("password", "").strip() device = request.form.get("device", "Unknown").strip() - username_regex = re.compile(USER_REGEX) - if not username or not username_regex.match(username) or not password: + if not username or not USER_REGEX.match(username) or not password: return "Username or Password is incorrect!", 400 user = Users.query.filter_by(username=username).first() diff --git a/TFR/server/auth.py b/TFR/server/auth.py index 762aab6..e880801 100644 --- a/TFR/server/auth.py +++ b/TFR/server/auth.py @@ -1,4 +1,3 @@ -import re import uuid from flask import Blueprint, render_template, request, flash, redirect, url_for @@ -24,12 +23,10 @@ def register(): username = request.form.get("username", None).strip() password = request.form.get("password", None).strip() confirm = request.form.get("confirm", None).strip() - - username_regex = re.compile(USER_REGEX) error = [] # Validate the form - if not username or not username_regex.match(username): + if not username or not USER_REGEX.match(username): error.append("Username is invalid! Must be alphanumeric, and can contain ._-") if not password or len(password) < 8: error.append("Password is too short! Must be at least 8 characters long.") @@ -61,11 +58,10 @@ def login(): # Get the form data username = request.form.get("username", None).strip() password = request.form.get("password", None).strip() - username_regex = re.compile(USER_REGEX) error = [] # Validate the form - if not username or not username_regex.match(username) or not password: + if not username or not USER_REGEX.match(username) or not password: error.append("Username or Password is incorrect!") user = Users.query.filter_by(username=username).first() diff --git a/TFR/server/config.py b/TFR/server/config.py index 1f2bc43..522dae0 100644 --- a/TFR/server/config.py +++ b/TFR/server/config.py @@ -1,35 +1,41 @@ from os import getenv +import re +SECRET_KEY = getenv("FLASK_KEY") + UPLOAD_DIR = "/data/uploads" -UPLOAD_EXTENSIONS = ["png", "jpg", "jpeg", "gif"] +UPLOAD_EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp"] UPLOAD_RESOLUTION = 512 UPLOAD_MAX_SIZE = 3 * 1024 * 1024 # 3MB GAME_VERSION = "alpha" -GAME_VERSIONS = ["alpha"] -GAME_DIFFICULTIES = [0, 1, 2, 3, 4] +GAME_DIFFICULTY = 0 -USER_REGEX = r"\b[A-Za-z0-9._-]+\b" -USER_EMAIL_REGEX = r"[^@]+@[^@]+\.[^@]+" +GAME_VERSIONS = { + "alpha": "Alpha", + "alpha-expo": "Alpha (Expo Build)", +} +GAME_DIFFICULTIES = { + 0: "Easy - Level 1", + 1: "Easy - Level 2", + 2: "Easy - Level 3", + 3: "Medium", + 4: "Hard", +} + +USER_REGEX = re.compile(r"\b[A-Za-z0-9._-]+\b") +USER_EMAIL_REGEX = re.compile(r"[^@]+@[^@]+\.[^@]+") MAX_TOP_SCORES = 15 MAX_SEARCH_RESULTS = 5 -# Postgres -SECRET_KEY = getenv("FLASK_KEY") - user = getenv("DB_USER") password = getenv("DB_PASSWORD") host = getenv("DB_HOST") db = getenv("DB_NAME") +port = 5432 -SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{user}:{password}@{host}:5432/{db}" +SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{user}:{password}@{host}:{port}/{db}" SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_POOL_RECYCLE = 621 - -""" -# SQLite -SECRET_KEY = "dev" -SQLALCHEMY_DATABASE_URI = "sqlite:///tfr.db" -""" diff --git a/TFR/server/static/images/controls.png b/TFR/server/static/images/controls.png new file mode 100644 index 0000000..4ce45ee Binary files /dev/null and b/TFR/server/static/images/controls.png differ diff --git a/TFR/server/templates/views/about.html b/TFR/server/templates/views/about.html index f635835..8d8aa97 100644 --- a/TFR/server/templates/views/about.html +++ b/TFR/server/templates/views/about.html @@ -3,6 +3,8 @@

What is The Front Rooms?

The Front Rooms is a game based on The Backrooms Genre of games.

+ Drawing of keyboard displaying controls +

Is my data secured?

Yes, all passwords and emails are hashed and salted, and at no point stored in plain text.

{% endblock %} \ No newline at end of file diff --git a/TFR/server/templates/views/scores.html b/TFR/server/templates/views/scores.html index 90f4d40..3580bb3 100644 --- a/TFR/server/templates/views/scores.html +++ b/TFR/server/templates/views/scores.html @@ -4,19 +4,18 @@