Major architectural refactoring to improve code organization, maintainability, and scalability: - Implement MVC pattern with clear separation of concerns - Organize code into blueprints for different functional areas (main, tenant, admin, api) - Create models layer to encapsulate all database operations - Create services layer for business logic (auth, product, barcode) - Implement application factory pattern for better testability - Add environment-based configuration management - Remove old monolithic app.py and consolidate routes New structure: - app/models/ - Database operations (Tenant, Product, ARField, Settings) - app/services/ - Business logic (Auth, Product, Barcode services) - app/blueprints/ - Controllers organized by function - app/config.py - Environment configurations - run.py - Application entry point All routes remain backward compatible. No changes to API or templates functionality.
26 lines
865 B
Python
26 lines
865 B
Python
import base64
|
|
from app.models import TenantModel
|
|
|
|
class AuthService:
|
|
"""Service for authentication logic"""
|
|
|
|
@staticmethod
|
|
def check_basic_auth(auth_header: str, tenant_id: str) -> bool:
|
|
"""Validate Basic authentication credentials for a tenant"""
|
|
if not auth_header or not auth_header.startswith('Basic '):
|
|
return False
|
|
|
|
try:
|
|
# Decode the base64 credentials
|
|
credentials = base64.b64decode(auth_header[6:]).decode('utf-8')
|
|
username, password = credentials.split(':', 1)
|
|
|
|
# Get tenant credentials from database (without creating)
|
|
tenant = TenantModel.get_by_id(tenant_id)
|
|
if tenant and username == tenant['username'] and password == tenant['password']:
|
|
return True
|
|
except Exception:
|
|
pass
|
|
|
|
return False
|