feat(auth-models): Add is_admin field to User model

This commit adds an is_admin field to the User model definition in user.py. It is set to False by default and has been updated in fake_users_db for both users. Also, there were some code formatting changes made in auth.py.
This commit is contained in:
gustavoschaedler 2023-06-21 15:54:56 +01:00
commit f855433652
2 changed files with 5 additions and 2 deletions

View file

@ -39,7 +39,7 @@ def create_access_token(data: dict, expires_delta: timedelta = None):
def authenticate_user(fake_db, username: str, password: str):
user = get_user(fake_db, username)
if not user:
return False
if not verify_password(password, user.hashed_password):
@ -53,7 +53,7 @@ async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]):
detail="Could not validate credentials",
headers={"WWW-Authenticate": "Bearer"},
)
try:
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
username: str = payload.get("sub")

View file

@ -6,6 +6,7 @@ class User(BaseModel):
email: str | None = None
full_name: str | None = None
disabled: bool | None = None
is_admin: bool | None = False
class UserInDB(User):
@ -19,6 +20,7 @@ fake_users_db = {
"email": "gustavopoa@gmail.com",
"hashed_password": "$2b$12$f4R8IHUaVxVchhpWrwhckeJXnPalW1vUbJzcvb1KeovJcuMwE861K", #secret
"disabled": False,
"is_admin": True,
},
"gustavo_disabled": {
"username": "gustavo_disabled",
@ -26,6 +28,7 @@ fake_users_db = {
"email": "gustavo_disabled@gmail.com",
"hashed_password": "$2b$12$f4R8IHUaVxVchhpWrwhckeJXnPalW1vUbJzcvb1KeovJcuMwE861K", #secret
"disabled": True,
"is_admin": False,
}
}