Spaces:
Runtime error
Runtime error
Download app/routers/auth.py from abdullah090809/FastAPI-Project: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/abdullah090809/FastAPI-Project/resolve/main/app/routers/auth.py
- Command line
-
hf download hf://spaces/abdullah090809/FastAPI-Project/app/routers/auth.py
-
curl -L -o auth.py https://huggingface.co/spaces/abdullah090809/FastAPI-Project/resolve/main/app/routers/auth.py
1.02 kB
| from fastapi.security.oauth2 import OAuth2PasswordRequestForm | |
| from fastapi import APIRouter, Depends, HTTPException, status | |
| from sqlalchemy.orm import Session | |
| from app.schemas import Token | |
| from app import utils | |
| from app.database import get_db | |
| from app.models import User | |
| from app.oauth2 import Create_Access_Token | |
| router = APIRouter(tags=["Authentication"]) | |
| def login(user_credentials: OAuth2PasswordRequestForm = Depends(), db: Session = Depends(get_db)): | |
| user=db.query(User).filter(User.email == user_credentials.username).first() | |
| if not user: | |
| raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,detail="Invalid Credentials") | |
| if not utils.verify(user_credentials.password,user.password): | |
| raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,detail="Invalid Credentials") | |
| access_token=Create_Access_Token(data={"id": user.id}) | |
| return { | |
| "access_token": access_token, | |
| "token_type": "bearer" | |
| } | |