Added first controls

This commit is contained in:
2025-11-26 20:53:12 +01:00
parent 459c89bae2
commit ce5328fe34
68 changed files with 37849 additions and 87048 deletions

View File

@@ -16,9 +16,10 @@ from ..auth.utils import (
logout_user,
get_user_info
)
from ..core.instances import InstancesManager
def setup_auth_routes(app, rt, mount_auth_app=True, sqlite_db_path="Users.db"):
def setup_auth_routes(app, rt, mount_auth_app=True, sqlite_db_path="Users.db", base_url=None):
"""
Setup all authentication and protected routes.
@@ -27,6 +28,7 @@ def setup_auth_routes(app, rt, mount_auth_app=True, sqlite_db_path="Users.db"):
rt: Route decorator from FastHTML
mount_auth_app: Whether to mount the auth FastApi API routes
sqlite_db_path: by default, create a new SQLite database at this path
base_url: Base URL for the application (default to localhost:5001 if not provided)
"""
# ============================================================================
@@ -61,7 +63,7 @@ def setup_auth_routes(app, rt, mount_auth_app=True, sqlite_db_path="Users.db"):
RedirectResponse on success, or LoginPage with error on failure
"""
# Attempt login
auth_data = login_user(email, password)
auth_data = login_user(email, password, base_url=base_url)
if auth_data:
# Login successful - store tokens in session
@@ -69,7 +71,7 @@ def setup_auth_routes(app, rt, mount_auth_app=True, sqlite_db_path="Users.db"):
session['refresh_token'] = auth_data['refresh_token']
# Get user info and store in session
user_info = get_user_info(auth_data['access_token'])
user_info = get_user_info(auth_data['access_token'], base_url=base_url)
if user_info:
session['user_info'] = user_info
@@ -116,7 +118,7 @@ def setup_auth_routes(app, rt, mount_auth_app=True, sqlite_db_path="Users.db"):
return RegisterPage(error_message="Password must be at least 8 characters long.")
# Attempt registration
result = register_user(email, username, password)
result = register_user(email, username, password, base_url=base_url)
if result:
# Registration successful - show success message and auto-login
@@ -180,6 +182,9 @@ def setup_auth_routes(app, rt, mount_auth_app=True, sqlite_db_path="Users.db"):
if refresh_token:
logout_user(refresh_token)
# release memory
InstancesManager.clear_session(session)
# Clear session
session.clear()