Bugs bugs bugs bugs bugs bugs

I love bugs
This commit is contained in:
Michał Gdula 2023-06-26 14:15:45 +01:00
parent 28d5f140c0
commit 377f20ce10
7 changed files with 34 additions and 12 deletions

View file

@ -1,4 +1,8 @@
{$THE_FRONT_ROOMS_DOMAIN} {$THE_FRONT_ROOMS_DOMAIN}
reverse_proxy tfr:8000
encode gzip
reverse_proxy tfr:8000 {
header_up X-Forwarded-For {http.request.remote.addr}
header_up X-Real-IP {http.request.remote.addr}
}
encode gzip

View file

@ -6,7 +6,7 @@ from werkzeug.security import check_password_hash
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
from .models import Scores, Sessions, Users from .models import Scores, Sessions, Users
from .extensions import db from .extensions import db, logger
from .config import ( from .config import (
GAME_VERSION, GAME_VERSION,
GAME_VERSIONS, GAME_VERSIONS,
@ -55,32 +55,34 @@ def post():
difficulty = request.form.get("difficulty", GAME_DIFFICULTY) difficulty = request.form.get("difficulty", GAME_DIFFICULTY)
score = request.form.get("score", 0) score = request.form.get("score", 0)
# logger.debug(f"Score upload attempt: {session_key} {version} {difficulty} {score}")
if not session_key: if not session_key:
return "No session key provided!" return "No session key provided!"
if not score: if not score:
return "Score is not valid!" return "Score is not valid!"
try: try:
float(score) score = float(score)
int(difficulty) difficulty = int(difficulty)
except TypeError: except TypeError:
return "Invalid score and difficulty must be valid numbers!" return "Invalid score and difficulty must be valid numbers!"
if int(difficulty) not in GAME_DIFFICULTIES: if difficulty not in GAME_DIFFICULTIES:
return "Invalid difficulty!" return "Invalid difficulty!"
if version not in GAME_VERSIONS: if version not in GAME_VERSIONS:
return "Invalid version!" return "Invalid version!"
# This is a fix for a bug in the game that we dunno how to actually fix # This is a fix for a bug in the game that we dunno how to actually fix
# if score < 10: if score < 10:
# return "Score is impossible!" return "Score is impossible!"
session_data = Sessions.query.filter_by(auth_key=session_key).first() session_data = Sessions.query.filter_by(auth_key=session_key).first()
if not session_data: if not session_data:
return "Authentication failed!" return "Authentication failed!"
score_upload = Scores( score_upload = Scores(
score=float(score), score=score,
difficulty=int(difficulty), difficulty=difficulty,
version=version, version=version,
user_id=session_data.user_id, user_id=session_data.user_id,
) )

View file

@ -77,4 +77,4 @@ def login():
login_user(user, remember=True) login_user(user, remember=True)
flash("Successfully logged in!", "success") flash("Successfully logged in!", "success")
return redirect(url_for("account.settings")) return redirect(url_for("account.get_settings"))

View file

@ -39,3 +39,5 @@ port = 5432
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{user}:{password}@{host}:{port}/{db}" SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{user}:{password}@{host}:{port}/{db}"
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_POOL_RECYCLE = 621 SQLALCHEMY_POOL_RECYCLE = 621
LOGS_DIR = "/data/logs"

View file

@ -1,9 +1,21 @@
import logging
from os import path
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate from flask_migrate import Migrate
from flask_assets import Environment from flask_assets import Environment
from flask_caching import Cache from flask_caching import Cache
from flask_login import LoginManager from flask_login import LoginManager
from .config import LOGS_DIR
logger = logging
logger.getLogger(path.join(LOGS_DIR, "server.log"))
logger.basicConfig(
level=logging.DEBUG,
format="%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s",
)
db = SQLAlchemy() db = SQLAlchemy()
migrate = Migrate() migrate = Migrate()
assets = Environment() assets = Environment()

View file

@ -54,7 +54,8 @@ function getSearch() {
el.innerHTML = user; el.innerHTML = user;
el.onmousedown = function (event) { el.onmousedown = function (event) {
event.preventDefault(); event.preventDefault();
search = user.toString(); search = document.querySelector('#search');
search.value = user.toString();
search.blur(); search.blur();
} }
hint.appendChild(el); hint.appendChild(el);

View file

@ -38,6 +38,7 @@ services:
volumes: volumes:
- ./TFR/storage/migrations:/data/migrations - ./TFR/storage/migrations:/data/migrations
- ./TFR/storage/uploads:/data/uploads - ./TFR/storage/uploads:/data/uploads
- ./TFR/storage/logs:/data/logs
environment: environment:
FLASK_KEY: ${THE_FRONT_ROOMS_SECRETE_KEY} FLASK_KEY: ${THE_FRONT_ROOMS_SECRETE_KEY}
DB_USER: ${POSTGRES_USER} DB_USER: ${POSTGRES_USER}