ميزة: تحديث صفحات الخصوصية والشروط مع تاريخ آخر تحديث ثابت وفترة احتفاظ ديناميكية بالملفات
ميزة: إضافة خدمة تحليلات لتكامل Google Analytics اختبار: تحديث اختبارات خدمة واجهة برمجة التطبيقات (API) لتعكس تغييرات نقاط النهاية إصلاح: تعديل خدمة واجهة برمجة التطبيقات (API) لدعم تحميل ملفات متعددة ومصادقة المستخدم ميزة: تطبيق مخزن مصادقة باستخدام Zustand لإدارة المستخدمين إصلاح: تحسين إعدادات Nginx لتعزيز الأمان ودعم التحليلات
This commit is contained in:
20
backend/app/utils/auth.py
Normal file
20
backend/app/utils/auth.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""Session helpers for authenticated routes."""
|
||||
from flask import session
|
||||
|
||||
|
||||
def get_current_user_id() -> int | None:
|
||||
"""Return the authenticated user id from session storage."""
|
||||
user_id = session.get("user_id")
|
||||
return user_id if isinstance(user_id, int) else None
|
||||
|
||||
|
||||
def login_user_session(user_id: int):
|
||||
"""Persist the authenticated user in the Flask session."""
|
||||
session.clear()
|
||||
session.permanent = True
|
||||
session["user_id"] = user_id
|
||||
|
||||
|
||||
def logout_user_session():
|
||||
"""Clear the active Flask session."""
|
||||
session.clear()
|
||||
@@ -20,7 +20,11 @@ class FileValidationError(Exception):
|
||||
super().__init__(self.message)
|
||||
|
||||
|
||||
def validate_file(file_storage, allowed_types: list[str] | None = None):
|
||||
def validate_file(
|
||||
file_storage,
|
||||
allowed_types: list[str] | None = None,
|
||||
size_limit_overrides: dict[str, int] | None = None,
|
||||
):
|
||||
"""
|
||||
Validate an uploaded file through multiple security layers.
|
||||
|
||||
@@ -65,7 +69,7 @@ def validate_file(file_storage, allowed_types: list[str] | None = None):
|
||||
file_size = file_storage.tell()
|
||||
file_storage.seek(0)
|
||||
|
||||
size_limits = config.get("FILE_SIZE_LIMITS", {})
|
||||
size_limits = size_limit_overrides or config.get("FILE_SIZE_LIMITS", {})
|
||||
max_size = size_limits.get(ext, 20 * 1024 * 1024) # Default 20MB
|
||||
|
||||
if file_size > max_size:
|
||||
|
||||
Reference in New Issue
Block a user