2026-03-04 22:01:58 +03:00
|
|
|
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()
|
2026-03-05 21:33:41 +03:00
|
|
|
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")
|
2026-03-04 22:01:58 +03:00
|
|
|
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()
|
2026-03-05 21:33:41 +03:00
|
|
|
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")
|
2026-03-04 22:01:58 +03:00
|
|
|
return errors
|