app/routers/demo.py: minor changes
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user