7323c12168
- Added join_requests.html template for displaying pending join requests. - Created join_team.html template for users to submit join requests. - Implemented request_processed.html template to show the result of join request processing. - Developed authentication utilities for user session management. - Introduced convenience redirects for common URL patterns. - Established team management routes and actions for creating, editing, and joining teams. - Added functionality for approving and denying join requests with email notifications. - Enhanced team views to include user permissions and team member details. - Implemented utility functions for team-related operations such as calculating total points and team rank.
27 lines
930 B
Python
27 lines
930 B
Python
from fastapi import Request
|
|
from sqlalchemy.orm import Session
|
|
from ..models import User
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def get_current_user_from_session(request: Request, db: Session):
|
|
"""Get the current user from the session."""
|
|
try:
|
|
if hasattr(request.state, "user") and request.state.user is not None:
|
|
# User is already in request state, return it
|
|
return request.state.user
|
|
|
|
if hasattr(request, "session"):
|
|
user_id = request.session.get("user_id")
|
|
if user_id:
|
|
user = db.query(User).filter(User.id == user_id).first()
|
|
if user:
|
|
# Set it in the request state for future use
|
|
request.state.user = user
|
|
return user
|
|
except Exception as e:
|
|
logger.error(f"Error retrieving user from session: {str(e)}")
|
|
|
|
return None
|