Add comprehensive documentation for LeagueLedger

- Created architecture overview in development/architecture.md
- Added installation guide in getting-started/installation.md
- Developed user guide with detailed instructions in user-guide/overview.md, user-guide/teams.md, user-guide/qr-codes.md
- Implemented social login setup documentation in social_login_setup.md
- Updated index.md to include links to new documentation sections
- Configured mkdocs.yml for site structure and theme
- Added requirements.txt for documentation dependencies
This commit is contained in:
Christian Krakau-Louis
2025-04-15 12:32:03 +02:00
parent 7323c12168
commit 6306abf6d9
26 changed files with 3350 additions and 132 deletions
+31 -2
View File
@@ -1,15 +1,19 @@
"""
Authentication utilities for LeagueLedger.
This module provides backward compatibility with the existing code while leveraging
the new Starlette authentication system.
"""
from typing import Optional
from fastapi import Request, Depends
from sqlalchemy.orm import Session
from ..db import get_db
from ..models import User, TeamMembership
from starlette.authentication import UnauthenticatedUser
async def get_current_user(request: Request, db: Session = Depends(get_db)) -> Optional[User]:
"""
Get the current authenticated user from the session.
Get the current authenticated user from the request.
Now uses request.user from Starlette authentication with fallback to session.
Args:
request: The FastAPI request object
@@ -18,6 +22,11 @@ async def get_current_user(request: Request, db: Session = Depends(get_db)) -> O
Returns:
User object if authenticated, None otherwise
"""
# First try to get user from Starlette authentication
if hasattr(request, "user") and request.user.is_authenticated:
return request.user
# Fallback to session-based authentication (for backward compatibility)
user_id = request.session.get("user_id")
if not user_id:
@@ -61,7 +70,7 @@ async def is_team_captain(
is_captain = db.query(TeamMembership).filter(
TeamMembership.team_id == team_id,
TeamMembership.user_id == user.id,
TeamMembership.role == "captain"
TeamMembership.is_captain == True # Changed from role="captain" to is_captain=True
).first()
return bool(is_captain)
@@ -69,6 +78,7 @@ async def is_team_captain(
async def is_admin(request: Request, db: Session = Depends(get_db)) -> bool:
"""
Check if the current user is an admin.
Now checks Starlette auth scopes first.
Args:
request: FastAPI request object
@@ -77,6 +87,11 @@ async def is_admin(request: Request, db: Session = Depends(get_db)) -> bool:
Returns:
True if the user is an admin, False otherwise
"""
# Check for 'admin' scope in Starlette auth
if hasattr(request, "auth") and request.auth and "admin" in request.auth.scopes:
return True
# Fallback to user object check
user = await get_current_user(request, db)
if not user:
@@ -97,6 +112,11 @@ async def requires_login(request: Request, db: Session = Depends(get_db)) -> Opt
"""
from fastapi import HTTPException, status
# Check Starlette auth first
if hasattr(request, "user") and request.user.is_authenticated:
return request.user
# Fallback to session check
user = await get_current_user(request, db)
if not user:
@@ -121,6 +141,12 @@ async def requires_admin(request: Request, db: Session = Depends(get_db)) -> Use
"""
from fastapi import HTTPException, status
# Check for admin scope in Starlette auth
if hasattr(request, "auth") and request.auth and "admin" in request.auth.scopes:
if hasattr(request, "user") and request.user.is_authenticated:
return request.user
# Fallback to user object check
user = await get_current_user(request, db)
if not user or not user.is_admin:
@@ -130,3 +156,6 @@ async def requires_admin(request: Request, db: Session = Depends(get_db)) -> Use
)
return user
# Note: For new code, consider using the decorators in app.auth.permissions instead
# of these dependency functions directly