Still no result

This commit is contained in:
DmitryGantimurov 2023-07-20 00:09:30 +03:00 committed by Dmitry Gantimurov
parent d2c7ce453e
commit b06306a20b
2 changed files with 8 additions and 7 deletions

View File

@ -167,7 +167,7 @@ async def login_for_access_token(
@app.get("/api/users/me/", response_model=schema.User) @app.get("/api/users/me/", response_model=schema.User)
async def read_users_me( async def read_users_me( #!!!!!!!!!!!
current_user: Annotated[User, Depends(get_current_active_user)] current_user: Annotated[User, Depends(get_current_active_user)]
): ):
return current_user return current_user

View File

@ -9,7 +9,7 @@ from passlib.context import CryptContext
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from sqlalchemy import select from sqlalchemy import select
from .db import SessionLocal, database from .db import Session, database
from .models import UserDatabase from .models import UserDatabase
from .schema import Token, TokenData, UserInDB, User from .schema import Token, TokenData, UserInDB, User
@ -42,14 +42,15 @@ def get_password_hash(password):
# проблема здесь # проблема здесь
def get_user(db: SessionLocal, email: str): def get_user(db: Session, 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).first()
print(user_with_required_email)
if user_with_required_email: if user_with_required_email:
return UserInDB(user_with_required_email) return user_with_required_email
return None return None
def authenticate_user(db: SessionLocal, email: str, password: str): def authenticate_user(db: Session, email: str, password: str):
user = get_user(db, email) user = get_user(db, email)
if not user: if not user:
return False return False
@ -69,7 +70,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)]): async def get_current_user(db: Session, 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",