update kontor-api to reflect api changes
This commit is contained in:
@@ -5,7 +5,7 @@ from fastapi import APIRouter, Body, HTTPException, status, Depends, Response
|
|||||||
from fastapi.security import OAuth2PasswordRequestForm
|
from fastapi.security import OAuth2PasswordRequestForm
|
||||||
|
|
||||||
from src.core.config import settings
|
from src.core.config import settings
|
||||||
from src.core.security import create_access_token, authenticate_user_by_username, get_current_active_user
|
from src.core.security import create_access_token, authenticate_user_by_email, get_current_active_user
|
||||||
from src.db.models.admin import Profile
|
from src.db.models.admin import Profile
|
||||||
from src.schema.admin import Token, ProfileModel
|
from src.schema.admin import Token, ProfileModel
|
||||||
from src.webapps.auth.forms import LoginForm
|
from src.webapps.auth.forms import LoginForm
|
||||||
@@ -31,7 +31,7 @@ def login_for_access_token(form_data: Annotated[OAuth2PasswordRequestForm, Depen
|
|||||||
|
|
||||||
# @router.post("/token-cookie", response_model=Token)
|
# @router.post("/token-cookie", response_model=Token)
|
||||||
def login_for_token_cookie(response: Response, form_data: LoginForm = Depends()):
|
def login_for_token_cookie(response: Response, form_data: LoginForm = Depends()):
|
||||||
user = authenticate_user_by_username(form_data.username, form_data.password) # type: ignore
|
user = authenticate_user_by_email(form_data.username, form_data.password) # type: ignore
|
||||||
if not user:
|
if not user:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ def get_current_user_from_token(token: str = Depends(oauth2_scheme)):
|
|||||||
except JWTError:
|
except JWTError:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
with SessionLocal() as db:
|
with SessionLocal() as db:
|
||||||
user = get_profile(username=username, db=db)
|
user = get_profile_by_email(email=username, db=db)
|
||||||
if user is None:
|
if user is None:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
return user
|
return user
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
from typing import AnyStr, Optional
|
from typing import Optional
|
||||||
|
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from src.db.models.admin import Profile
|
from src.db.models.admin import Profile
|
||||||
|
|
||||||
|
|
||||||
def get_profile_by_username(username: AnyStr, db: Session) -> Optional[Profile]:
|
def get_profile_by_username(username: str, db: Session) -> Optional[Profile]:
|
||||||
profile = db.query(Profile).filter(Profile.user_name == username).first()
|
profile = db.query(Profile).filter(Profile.user_name == username).first()
|
||||||
return profile
|
return profile
|
||||||
|
|
||||||
def get_profile_by_email(email: AnyStr, db: Session) -> Optional[Profile]:
|
def get_profile_by_email(email: str, db: Session) -> Optional[Profile]:
|
||||||
profile = db.query(Profile).filter(Profile.email == email).first()
|
profile = db.query(Profile).filter(Profile.email == email).first()
|
||||||
return profile
|
return profile
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user