mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-20 05:54:19 +02:00
rename SessionDependency to DbSessionDependency
This commit is contained in:
@@ -8,10 +8,12 @@ from jwt.exceptions import InvalidTokenError
|
||||
from pydantic import BaseModel
|
||||
|
||||
from auth.config import AuthConfig
|
||||
from database import SessionDependency
|
||||
from database import DbSessionDependency
|
||||
from database.users import User
|
||||
|
||||
|
||||
# TODO: evaluate FASTAPI-Users package
|
||||
|
||||
class Token(BaseModel):
|
||||
access_token: str
|
||||
token_type: str
|
||||
@@ -28,7 +30,7 @@ oauth2_scheme = OAuth2PasswordBearer(tokenUrl="api/v1/token")
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
async def get_current_user(db: SessionDependency, token: str = Depends(oauth2_scheme)) -> User:
|
||||
async def get_current_user(db: DbSessionDependency, token: str = Depends(oauth2_scheme)) -> User:
|
||||
credentials_exception = HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Could not validate credentials",
|
||||
|
||||
@@ -6,7 +6,7 @@ from fastapi.security import OAuth2PasswordRequestForm
|
||||
from sqlmodel import select
|
||||
|
||||
from auth import Token, create_access_token, router
|
||||
from database import SessionDependency
|
||||
from database import DbSessionDependency
|
||||
from database.users import User
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ def get_password_hash(password: str) -> str:
|
||||
return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8")
|
||||
|
||||
|
||||
def authenticate_user(db: SessionDependency, email: str, password: str) -> bool | User:
|
||||
def authenticate_user(db: DbSessionDependency, email: str, password: str) -> bool | User:
|
||||
"""
|
||||
|
||||
:param email: email of the USER
|
||||
@@ -39,7 +39,7 @@ def authenticate_user(db: SessionDependency, email: str, password: str) -> bool
|
||||
@router.post("/token")
|
||||
async def login_for_access_token(
|
||||
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
|
||||
db: SessionDependency,
|
||||
db: DbSessionDependency,
|
||||
) -> Token:
|
||||
user = authenticate_user(db,form_data.username, form_data.password)
|
||||
if not user:
|
||||
|
||||
Reference in New Issue
Block a user