Refactor application to MVC architecture with Flask blueprints
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.
This commit is contained in:
25
src/app/services/auth_service.py
Normal file
25
src/app/services/auth_service.py
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
Reference in New Issue
Block a user