This commit is contained in:
2026-10-18 01:14:08 +03:00
parent 2083e4d264
commit d512f315fa
3 changed files with 7 additions and 15 deletions
-13
View File
@@ -1,13 +0,0 @@
# Copy to .env for your LOCAL synthetic test environment; never commit .env.
# These are logical interface suggestions; map actual framework names in REPORT.md.
APP_HOST=0.0.0.0
APP_PORT=8080
APP_ENV=lab
SESSION_TTL_SECONDS=3600
# Choose credentials locally. File paths contain no secret values.
DATABASE_URL_FILE=/run/secrets/database_url
# Optional on 3, required use on 4 in lab2; Redis OR Valkey:
SESSION_STORE=postgres
CACHE_URL_FILE=/run/secrets/cache_url
API_REPLICAS=2
IDEMPOTENCY_TTL_SECONDS=86400
+6 -2
View File
@@ -1,6 +1,7 @@
"""Business rules for MTUSI Messenger Lab3.""" """Business rules for MTUSI Messenger Lab3."""
from __future__ import annotations from __future__ import annotations
import asyncio
import hashlib import hashlib
import json import json
import re import re
@@ -103,11 +104,13 @@ async def register_user(
display_name: str, display_name: str,
password: str, password: str,
) -> dict[str, Any]: ) -> dict[str, Any]:
# Argon2 is CPU-bound (~0.5-1 s); off the event loop so /health/ready keeps answering.
password_hash = await asyncio.to_thread(hash_password, password)
user = await repositories.create_user( user = await repositories.create_user(
db, db,
username=username, username=username,
display_name=display_name, display_name=display_name,
password_hash=hash_password(password), password_hash=password_hash,
) )
if user is None: if user is None:
@@ -132,7 +135,8 @@ async def create_user_session(
username, password = credentials username, password = credentials
user = await repositories.get_user_by_username(db, username) user = await repositories.get_user_by_username(db, username)
if user is None or not verify_password( if user is None or not await asyncio.to_thread(
verify_password,
user["password_hash"], user["password_hash"],
password, password,
): ):
+1
View File
@@ -1,3 +1,4 @@
#file: noinspection ComposeUnknownValues
# Lab3: client -> HAProxy -> API x N -> PostgreSQL (source of truth: data, # Lab3: client -> HAProxy -> API x N -> PostgreSQL (source of truth: data,
# sessions, idempotency keys) + Valkey (shared session cache from lab2). # sessions, idempotency keys) + Valkey (shared session cache from lab2).
# Start: see REPORT.md, "Запуск из чистого clone". # Start: see REPORT.md, "Запуск из чистого clone".