added encryption
This commit is contained in:
@@ -14,7 +14,7 @@ router = APIRouter()
|
||||
async def register_user(user_data: UserCreate):
|
||||
"""
|
||||
Register or get user (idempotent).
|
||||
|
||||
|
||||
Uses upsert pattern to ensure one user per email.
|
||||
If user already exists, returns existing user.
|
||||
Called after Firebase Google Auth on frontend.
|
||||
@@ -43,7 +43,8 @@ async def register_user(user_data: UserCreate):
|
||||
# Fetch the user (either newly created or existing)
|
||||
user = db.users.find_one({"email": user_data.email})
|
||||
if not user:
|
||||
raise HTTPException(status_code=500, detail="Failed to retrieve user after upsert")
|
||||
raise HTTPException(
|
||||
status_code=500, detail="Failed to retrieve user after upsert")
|
||||
|
||||
return {
|
||||
"id": str(user["_id"]),
|
||||
@@ -56,7 +57,8 @@ async def register_user(user_data: UserCreate):
|
||||
"message": "User registered successfully" if result.upserted_id else "User already exists"
|
||||
}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Registration failed: {str(e)}")
|
||||
raise HTTPException(
|
||||
status_code=500, detail=f"Registration failed: {str(e)}")
|
||||
|
||||
|
||||
@router.get("/by-email/{email}", response_model=dict)
|
||||
@@ -79,7 +81,8 @@ async def get_user_by_email(email: str):
|
||||
"updatedAt": user["updatedAt"].isoformat()
|
||||
}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Failed to fetch user: {str(e)}")
|
||||
raise HTTPException(
|
||||
status_code=500, detail=f"Failed to fetch user: {str(e)}")
|
||||
|
||||
|
||||
@router.get("/{user_id}", response_model=dict)
|
||||
@@ -103,8 +106,10 @@ async def get_user_by_id(user_id: str):
|
||||
}
|
||||
except Exception as e:
|
||||
if "invalid ObjectId" in str(e).lower():
|
||||
raise HTTPException(status_code=400, detail="Invalid user ID format")
|
||||
raise HTTPException(status_code=500, detail=f"Failed to fetch user: {str(e)}")
|
||||
raise HTTPException(
|
||||
status_code=400, detail="Invalid user ID format")
|
||||
raise HTTPException(
|
||||
status_code=500, detail=f"Failed to fetch user: {str(e)}")
|
||||
|
||||
|
||||
@router.put("/{user_id}", response_model=dict)
|
||||
@@ -139,7 +144,8 @@ async def update_user(user_id: str, user_data: UserUpdate):
|
||||
}
|
||||
except Exception as e:
|
||||
if "invalid ObjectId" in str(e).lower():
|
||||
raise HTTPException(status_code=400, detail="Invalid user ID format")
|
||||
raise HTTPException(
|
||||
status_code=400, detail="Invalid user ID format")
|
||||
raise HTTPException(status_code=500, detail=f"Update failed: {str(e)}")
|
||||
|
||||
|
||||
@@ -164,8 +170,10 @@ async def delete_user(user_id: str):
|
||||
}
|
||||
except Exception as e:
|
||||
if "invalid ObjectId" in str(e).lower():
|
||||
raise HTTPException(status_code=400, detail="Invalid user ID format")
|
||||
raise HTTPException(status_code=500, detail=f"Deletion failed: {str(e)}")
|
||||
raise HTTPException(
|
||||
status_code=400, detail="Invalid user ID format")
|
||||
raise HTTPException(
|
||||
status_code=500, detail=f"Deletion failed: {str(e)}")
|
||||
|
||||
# Delete all entries by user
|
||||
db.entries.delete_many({"userId": user_id})
|
||||
|
||||
Reference in New Issue
Block a user