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:
parent
6d78aefa62
commit
f855433652
2 changed files with 5 additions and 2 deletions
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue