3 lab
This commit is contained in:
@@ -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
@@ -1,6 +1,7 @@
|
||||
"""Business rules for MTUSI Messenger Lab3."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
@@ -103,11 +104,13 @@ async def register_user(
|
||||
display_name: str,
|
||||
password: str,
|
||||
) -> 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(
|
||||
db,
|
||||
username=username,
|
||||
display_name=display_name,
|
||||
password_hash=hash_password(password),
|
||||
password_hash=password_hash,
|
||||
)
|
||||
|
||||
if user is None:
|
||||
@@ -132,7 +135,8 @@ async def create_user_session(
|
||||
username, password = credentials
|
||||
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"],
|
||||
password,
|
||||
):
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#file: noinspection ComposeUnknownValues
|
||||
# Lab3: client -> HAProxy -> API x N -> PostgreSQL (source of truth: data,
|
||||
# sessions, idempotency keys) + Valkey (shared session cache from lab2).
|
||||
# Start: see REPORT.md, "Запуск из чистого clone".
|
||||
|
||||
Reference in New Issue
Block a user