auth_service.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """
  2. Authentication Service for user queries.
  3. Local registration, login, and token refresh have been removed.
  4. All authentication now goes through SSO (see oauth_service.py).
  5. """
  6. from database import get_db_connection
  7. from models import User
  8. from fastapi import HTTPException, status
  9. class AuthService:
  10. """Service for user query operations."""
  11. @staticmethod
  12. def get_current_user(user_id: str) -> User:
  13. """
  14. Get user by ID.
  15. Args:
  16. user_id: User unique identifier
  17. Returns:
  18. User object
  19. Raises:
  20. HTTPException: 404 if user not found
  21. """
  22. with get_db_connection() as conn:
  23. cursor = conn.cursor()
  24. cursor.execute(
  25. "SELECT * FROM users WHERE id = ?",
  26. (user_id,)
  27. )
  28. row = cursor.fetchone()
  29. if not row:
  30. raise HTTPException(
  31. status_code=status.HTTP_404_NOT_FOUND,
  32. detail="用户不存在"
  33. )
  34. return User.from_row(row)