Major update 2 / login

This commit is contained in:
2026-04-26 16:33:04 +03:00
parent 5bff9a287d
commit e8fd35105f
15 changed files with 999 additions and 96 deletions

39
db.py
View File

@@ -1,5 +1,6 @@
import sqlite3
import os
import secrets
DB_PATH = os.path.join(os.path.dirname(__file__), 'grepo.db')
@@ -81,5 +82,43 @@ def init_db():
except Exception:
pass # column already exists
# Users — website admin accounts
c.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
)
''')
# Clans — groups owned by a user, identified by a unique clan_key
c.execute('''
CREATE TABLE IF NOT EXISTS clans (
id INTEGER PRIMARY KEY AUTOINCREMENT,
owner_id INTEGER NOT NULL REFERENCES users(id),
name TEXT NOT NULL,
clan_key TEXT NOT NULL UNIQUE,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
)
''')
# Clan members — links Grepolis player_ids to a clan
c.execute('''
CREATE TABLE IF NOT EXISTS clan_members (
id INTEGER PRIMARY KEY AUTOINCREMENT,
clan_id INTEGER NOT NULL REFERENCES clans(id),
player_id TEXT NOT NULL,
player_name TEXT,
joined_at TEXT NOT NULL DEFAULT (datetime('now')),
UNIQUE(clan_id, player_id)
)
''')
conn.commit()
conn.close()
def generate_clan_key():
"""Generate a short, unique, human-readable clan key."""
return secrets.token_urlsafe(8).upper()[:10]