Spaces:
Sleeping
Sleeping
Download app/api/auth.py from vara201/simple-rag: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/spaces/vara201/simple-rag/resolve/main/app/api/auth.py
- Command line
-
hf download hf://spaces/vara201/simple-rag/app/api/auth.py
-
curl -L -o auth.py https://huggingface.co/spaces/vara201/simple-rag/resolve/main/app/api/auth.py
2.27 kB
| from fastapi import APIRouter | |
| from fastapi import Depends | |
| from sqlalchemy.ext.asyncio import AsyncSession | |
| from app.core.database import get_db | |
| from app.schemas.user import ( | |
| UserCreate, | |
| UserLogin, | |
| UserResponse, | |
| TokenResponse | |
| ) | |
| from fastapi.security import OAuth2PasswordRequestForm | |
| from app.services.auth_service import AuthService | |
| from app.core.dependencies import ( | |
| get_current_user | |
| ) | |
| router = APIRouter( | |
| prefix="/auth", | |
| tags=["Authentication"] | |
| ) | |
| async def register( | |
| payload: UserCreate, | |
| db: AsyncSession = Depends(get_db) | |
| ): | |
| return await AuthService.register( | |
| db, | |
| payload | |
| ) | |
| async def login( | |
| payload: OAuth2PasswordRequestForm = Depends(), | |
| db: AsyncSession = Depends(get_db) | |
| ): | |
| return await AuthService.login( | |
| db, | |
| payload.username, | |
| payload.password | |
| ) | |
| async def me( | |
| current_user=Depends( | |
| get_current_user | |
| ) | |
| ): | |
| return current_user | |
| async def logout( | |
| current_user=Depends( | |
| get_current_user | |
| ) | |
| ): | |
| """ | |
| Logout endpoint (mainly for client-side token cleanup) | |
| """ | |
| return { | |
| "message": "Successfully logged out", | |
| "status": "success" | |
| } | |
| async def update_profile( | |
| username: str = None, | |
| email: str = None, | |
| db: AsyncSession = Depends(get_db), | |
| current_user=Depends( | |
| get_current_user | |
| ) | |
| ): | |
| """ | |
| Update user profile (username and/or email) | |
| """ | |
| return await AuthService.update_profile( | |
| db, | |
| current_user, | |
| username, | |
| ) | |
| async def delete_account( | |
| db: AsyncSession = Depends(get_db), | |
| current_user=Depends( | |
| get_current_user | |
| ) | |
| ): | |
| """ | |
| Delete user account and all associated data | |
| """ | |
| return await AuthService.delete_account( | |
| db, | |
| current_user | |
| ) |