| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- """
- Authentication Service for user queries.
- Local registration, login, and token refresh have been removed.
- All authentication now goes through SSO (see oauth_service.py).
- """
- from database import get_db_connection
- from models import User
- from fastapi import HTTPException, status
- class AuthService:
- """Service for user query operations."""
- @staticmethod
- def get_current_user(user_id: str) -> User:
- """
- Get user by ID.
- Args:
- user_id: User unique identifier
- Returns:
- User object
- Raises:
- HTTPException: 404 if user not found
- """
- with get_db_connection() as conn:
- cursor = conn.cursor()
- cursor.execute(
- "SELECT * FROM users WHERE id = ?",
- (user_id,)
- )
- row = cursor.fetchone()
- if not row:
- raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="用户不存在"
- )
- return User.from_row(row)
|