Migrate web app from Python/FastAPI to Node.js/TypeScript
Replace the entire Python/FastAPI backend with a Node.js/TypeScript stack: - Framework: Hono + @hono/node-server - Templates: Nunjucks (.njk) replacing Jinja2 (.html) - ORM: Drizzle ORM with mysql2 (same MariaDB schema, no migrations needed) - Sessions: hono-sessions with CookieStore - CSS: Pico CSS v2 replacing Bootstrap 5 (Bootstrap Icons CDN kept) - Dev: tsx watch; Prod: tsc + node dist/index.js Original Python app preserved in web-python/ as backup. Updated Dockerfile.web and docker-compose.yml for Node.js deployment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
52
web-python/schemas.py
Normal file
52
web-python/schemas.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import re
|
||||
|
||||
|
||||
def validate_registration(data: dict) -> list[str]:
|
||||
errors = []
|
||||
if not data.get("first_name", "").strip():
|
||||
errors.append("Введите имя")
|
||||
if not data.get("last_name", "").strip():
|
||||
errors.append("Введите фамилию")
|
||||
email = data.get("email", "").strip()
|
||||
if not email or not re.match(r"^[^@]+@[^@]+\.[^@]+$", email):
|
||||
errors.append("Введите корректный email")
|
||||
phone = data.get("phone", "").strip()
|
||||
if not phone or not re.match(r"^\+7 \(\d{3}\) \d{3}-\d{2}-\d{2}$", phone):
|
||||
errors.append("Введите телефон в формате +7 (XXX) XXX-XX-XX")
|
||||
password = data.get("password", "")
|
||||
if len(password) < 8:
|
||||
errors.append("Пароль должен быть не менее 8 символов")
|
||||
if password != data.get("password_confirm", ""):
|
||||
errors.append("Пароли не совпадают")
|
||||
return errors
|
||||
|
||||
|
||||
def validate_login(data: dict) -> list[str]:
|
||||
errors = []
|
||||
if not data.get("email", "").strip():
|
||||
errors.append("Введите email")
|
||||
if not data.get("password", ""):
|
||||
errors.append("Введите пароль")
|
||||
return errors
|
||||
|
||||
|
||||
def validate_reset_password(data: dict) -> list[str]:
|
||||
errors = []
|
||||
password = data.get("password", "")
|
||||
if len(password) < 8:
|
||||
errors.append("Пароль должен быть не менее 8 символов")
|
||||
if password != data.get("password_confirm", ""):
|
||||
errors.append("Пароли не совпадают")
|
||||
return errors
|
||||
|
||||
|
||||
def validate_profile(data: dict) -> list[str]:
|
||||
errors = []
|
||||
if not data.get("first_name", "").strip():
|
||||
errors.append("Введите имя")
|
||||
if not data.get("last_name", "").strip():
|
||||
errors.append("Введите фамилию")
|
||||
phone = data.get("phone", "").strip()
|
||||
if not phone or not re.match(r"^\+7 \(\d{3}\) \d{3}-\d{2}-\d{2}$", phone):
|
||||
errors.append("Введите телефон в формате +7 (XXX) XXX-XX-XX")
|
||||
return errors
|
||||
Reference in New Issue
Block a user