Download app/routes/auth.py from Noor2623/Smart-Query-Routing-Email-Automation-System: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/Noor2623/Smart-Query-Routing-Email-Automation-System/resolve/main/app/routes/auth.py
- Command line
-
hf download hf://spaces/Noor2623/Smart-Query-Routing-Email-Automation-System/app/routes/auth.py
-
curl -L -o auth.py https://huggingface.co/spaces/Noor2623/Smart-Query-Routing-Email-Automation-System/resolve/main/app/routes/auth.py
1.34 kB
| from fastapi import APIRouter, Depends, HTTPException, status | |
| from sqlalchemy.orm import Session | |
| from app.dependencies import get_current_user, get_db | |
| from app.models.user import User | |
| from app.schemas.auth import LoginRequest, SignupRequest, TokenResponse | |
| from app.schemas.user import UserRead | |
| from app.services.auth_service import ( | |
| authenticate_user, | |
| build_token_response, | |
| create_user, | |
| ) | |
| router = APIRouter(prefix="/auth", tags=["auth"]) | |
| def signup(payload: SignupRequest, db: Session = Depends(get_db)) -> TokenResponse: | |
| try: | |
| user = create_user(db, payload) | |
| except ValueError as exc: | |
| raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc)) from exc | |
| return build_token_response(user) | |
| def login(payload: LoginRequest, db: Session = Depends(get_db)) -> TokenResponse: | |
| try: | |
| user = authenticate_user(db, payload) | |
| except ValueError as exc: | |
| raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=str(exc)) from exc | |
| return build_token_response(user) | |
| def read_me(current_user: User = Depends(get_current_user)) -> User: | |
| return current_user | |