Prepare to use another auth code

This commit is contained in:
DmitryGantimurov 2023-07-19 23:24:42 +03:00 committed by Dmitry Gantimurov
parent 8513e8610b
commit d2c7ce453e
2 changed files with 5 additions and 3 deletions

View File

@ -19,8 +19,10 @@ class User(BaseModel):
phone: Union[int, None] = None phone: Union[int, None] = None
email: str email: str
name: Union[str, None] = None name: Union[str, None] = None
surname: Union[str, None] = None surname: str
class Config:
orm_mode = True
class UserInDB(User): class UserInDB(User):
password: str password: str

View File

@ -42,7 +42,7 @@ def get_password_hash(password):
# проблема здесь # проблема здесь
def get_user(db: SessionLocal, email: str, response_model=User): def get_user(db: SessionLocal, email: str):
user_with_required_email = db.query(UserDatabase).filter(UserDatabase.email == email).one() user_with_required_email = db.query(UserDatabase).filter(UserDatabase.email == email).one()
if user_with_required_email: if user_with_required_email:
return UserInDB(user_with_required_email) return UserInDB(user_with_required_email)
@ -69,7 +69,7 @@ def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None
return encoded_jwt return encoded_jwt
async def get_current_user(db: SessionLocal, token: Annotated[str, Depends(oauth2_scheme)], response_model=User): async def get_current_user(db: SessionLocal, token: Annotated[str, Depends(oauth2_scheme)]):
credentials_exception = HTTPException( credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials", detail="Could not validate credentials",