app/routers/demo.py: minor changes #2

Closed
Aklivtsov wants to merge 1 commits from dev into main
Showing only changes of commit fd55ce7987 - Show all commits

View File

@@ -27,23 +27,23 @@ users_db: dict[str, UserSchema] = {
sam.username: sam sam.username: sam
} }
def validate_auth_user( def validate_auth_user(username: str = Form(), password: str = Form()) -> UserSchema | HTTPException:
username: str = Form(),
password: str = Form() if not (user := users_db.get(username)):
): raise HTTPException(
unauthed_exc = HTTPException( status_code=401,
detail="Invalid username or password"
)
is_passwd_valid = validate_password(password=password, hashed_password=user.password)
if not is_passwd_valid:
raise HTTPException(
status_code=401, status_code=401,
detail="Invalid username or password" detail="Invalid username or password"
) )
if not (user := users_db.get(username)):
raise unauthed_exc
if validate_password(
password=password,
hashed_password=user.password
):
return user return user
raise unauthed_exc
def get_current_token_payload( def get_current_token_payload(
credentials: HTTPAuthorizationCredentials = Depends(http_bearer) credentials: HTTPAuthorizationCredentials = Depends(http_bearer)