Nuevo Commit
This commit is contained in:
@@ -24,7 +24,12 @@ def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
|
||||
|
||||
def decode_access_token(token: str):
|
||||
try:
|
||||
print(f"Attempting to decode token: {token[:50]}...") # Debug
|
||||
print(f"Using SECRET_KEY: {settings.SECRET_KEY[:20]}...") # Debug
|
||||
print(f"Using ALGORITHM: {settings.ALGORITHM}") # Debug
|
||||
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM])
|
||||
print(f"Successfully decoded payload: {payload}") # Debug
|
||||
return payload
|
||||
except JWTError:
|
||||
except JWTError as e:
|
||||
print(f"JWT decode error: {e}") # Debug
|
||||
return None
|
||||
|
||||
@@ -34,14 +34,18 @@ def get_current_user(
|
||||
):
|
||||
token = credentials.credentials
|
||||
payload = decode_access_token(token)
|
||||
print(f"Token payload: {payload}") # Debug
|
||||
if payload is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Token inválido o expirado"
|
||||
)
|
||||
|
||||
user = db.query(models.User).filter(models.User.id == payload.get("sub")).first()
|
||||
user_id = int(payload.get("sub"))
|
||||
print(f"Looking for user ID: {user_id}") # Debug
|
||||
user = db.query(models.User).filter(models.User.id == user_id).first()
|
||||
if user is None:
|
||||
print(f"User not found with ID: {user_id}") # Debug
|
||||
raise HTTPException(status_code=404, detail="Usuario no encontrado")
|
||||
|
||||
return user
|
||||
@@ -79,7 +83,7 @@ def login(user_login: schemas.UserLogin, db: Session = Depends(get_db)):
|
||||
detail="Usuario o contraseña incorrectos"
|
||||
)
|
||||
|
||||
access_token = create_access_token(data={"sub": user.id, "role": user.role})
|
||||
access_token = create_access_token(data={"sub": str(user.id), "role": user.role})
|
||||
return {
|
||||
"access_token": access_token,
|
||||
"token_type": "bearer",
|
||||
@@ -254,7 +258,7 @@ def get_inspection(
|
||||
current_user: models.User = Depends(get_current_user)
|
||||
):
|
||||
inspection = db.query(models.Inspection).options(
|
||||
joinedload(models.Inspection.checklist),
|
||||
joinedload(models.Inspection.checklist).joinedload(models.Checklist.questions),
|
||||
joinedload(models.Inspection.mechanic),
|
||||
joinedload(models.Inspection.answers).joinedload(models.Answer.question),
|
||||
joinedload(models.Inspection.answers).joinedload(models.Answer.media_files)
|
||||
|
||||
@@ -167,11 +167,11 @@ class MediaFile(MediaFileBase):
|
||||
class ChecklistWithQuestions(Checklist):
|
||||
questions: List[Question] = []
|
||||
|
||||
class InspectionDetail(Inspection):
|
||||
checklist: Checklist
|
||||
mechanic: User
|
||||
answers: List[Answer] = []
|
||||
|
||||
class AnswerWithMedia(Answer):
|
||||
media_files: List[MediaFile] = []
|
||||
question: Question
|
||||
|
||||
class InspectionDetail(Inspection):
|
||||
checklist: ChecklistWithQuestions
|
||||
mechanic: User
|
||||
answers: List[AnswerWithMedia] = []
|
||||
|
||||
Reference in New Issue
Block a user