From a0bc0f0febc0906fb37a51ee611298e2694c322e Mon Sep 17 00:00:00 2001 From: iamBadgers Date: Wed, 22 Apr 2026 19:18:31 -0700 Subject: [PATCH] Initial skellies for the user stuff --- src/container_managment.py | 25 ++++++++----- src/database.py | 10 +++++ src/game_tables.py | 4 +- src/main.py | 1 + src/users.py | 75 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 src/users.py diff --git a/src/container_managment.py b/src/container_managment.py index b5d53c0..67259dc 100644 --- a/src/container_managment.py +++ b/src/container_managment.py @@ -22,8 +22,7 @@ def build_container_routing_labels(prefix: str, strip_prefix=True): labels = {} labels[router_key] = "Host(`{host_name}`) && PathPrefix(`/{prefix}`)".format( - host_name=host_name, - prefix=prefix + host_name=host_name, prefix=prefix ) if strip_prefix: labels[middleware_key] = "/{prefix}".format(prefix=prefix) @@ -31,6 +30,7 @@ def build_container_routing_labels(prefix: str, strip_prefix=True): return labels + def delete_container(docker_id) -> bool: if not docker_id: return False @@ -43,6 +43,7 @@ def delete_container(docker_id) -> bool: except docker.errors.NotFound, docker.errors.APIError: return False + def stop_container(docker_id) -> bool: try: client = docker.from_env() @@ -56,7 +57,9 @@ def stop_container(docker_id) -> bool: def start_foundry_container(table: GameTable, key: KeyTable): client = docker.from_env() container = None - networkName = client.containers.get(socket.gethostname()).attrs["HostConfig"]["NetworkMode"] + networkName = client.containers.get(socket.gethostname()).attrs["HostConfig"][ + "NetworkMode" + ] data_bind = os.environ.get("FOUNDRY_DATA_BIND") data_volume = os.environ.get("FOUNDRY_DATA_VOL") @@ -83,19 +86,23 @@ def start_foundry_container(table: GameTable, key: KeyTable): if data_volume: - os.makedirs("/data/{prefix}".format(prefix=table.game_table_link), exist_ok=True) + os.makedirs( + "/data/{prefix}".format(prefix=table.game_table_link), exist_ok=True + ) mounts = [ docker.types.Mount( target="/data", source=data_volume, type="volume", - subpath=table.game_table_link), + subpath=table.game_table_link, + ), docker.types.Mount( target="/data/container_cache", source=data_volume, type="volume", - subpath="container_cache") + subpath="container_cache", + ), ] container = client.containers.run( @@ -105,14 +112,14 @@ def start_foundry_container(table: GameTable, key: KeyTable): environment=environment, ports=ports, detach=True, - network=networkName + network=networkName, ) else: volumes = { "{data_bind}/{prefix}".format( data_bind=os.environ.get("FOUNDRY_DATA_BIND"), - prefix=table.game_table_link, + prefix=table.game_table_link, ): {"bind": "/data", "mode": "rw"}, "{data_bind}/container_cache".format( data_bind=os.environ.get("FOUNDRY_DATA_BIND") @@ -126,7 +133,7 @@ def start_foundry_container(table: GameTable, key: KeyTable): environment=environment, ports=ports, detach=True, - network=networkName + network=networkName, ) return container.id diff --git a/src/database.py b/src/database.py index 89d4652..f47057a 100644 --- a/src/database.py +++ b/src/database.py @@ -32,11 +32,21 @@ CREATE TABLE IF NOT EXISTS "game_keys" ( ); """ +_user_table_create = """ +CREATE TABLE IF NOT EXISTS "" ( + "id": INTEGER NOT NULL, + "username": TEXT NOT NULL, + "hash": TEXT NOT NULL, + PRIMARY KEY ("ID) +); +""" + def init_db(connection): with SmartCursor(connection=connection) as smart_cursor: smart_cursor.execute(_game_table_create) smart_cursor.execute(_key_table_create) + smart_cursor.execute(_user_table_create) connection.commit() diff --git a/src/game_tables.py b/src/game_tables.py index 753f56a..4e90c87 100644 --- a/src/game_tables.py +++ b/src/game_tables.py @@ -53,7 +53,9 @@ class GameTable: def commit(self, cursor): if not self._created: - self._game_table_id = cursor.execute("""SELECT MAX(game_table_id) + 1 FROM game_tables""").fetchone()[0] + self._game_table_id = cursor.execute( + """SELECT MAX(game_table_id) + 1 FROM game_tables""" + ).fetchone()[0] cursor.execute( """INSERT INTO game_tables diff --git a/src/main.py b/src/main.py index 9603390..bd301f6 100644 --- a/src/main.py +++ b/src/main.py @@ -5,6 +5,7 @@ from database import SmartCursor, get_db, init_db import tables import os + def create_app(): app = Flask(__name__) diff --git a/src/users.py b/src/users.py new file mode 100644 index 0000000..707e389 --- /dev/null +++ b/src/users.py @@ -0,0 +1,75 @@ +from typeing import List +from flask import Blueprint, current_app +from werkzeug.security import generate_password_hash, check_password_hash + + +class User: + _id: int + _username: str + _hash: str + _updated: bool + _created: bool + _delete: bool + + def __init__( + self, + id, + username, + hash, + created: bool = False, + updated: bool = False, + delete: bool = False, + ): + return + + def check_password(self, password: str): + return + + def commit(self): + return + + @property + def hash(self): + return self._hash + + @hash.setter + def set_hash(self, password: str): + self._updated = False + self._hash = generate_password_hash(password) + + @property + def username(self): + return self.username + + @username.setter + def set_username(self, username): + self._updated = False + self._username = username + + +class UserService: + + def __init__(): + return + + def read_by_username(username: str) -> User: + return + + def read_all() -> List[User]: + return [] + + def check_login(username: str, password: str): + return; + + +users = Blueprint("users_api", __name__) + + +@users.route("/login", method=["POST"]) +def login(): + return + + +@users.route("/logout", method=["POST"]) +def logout(): + return