From 642580ccd575cd94e863d528e9021e82abffc74f Mon Sep 17 00:00:00 2001 From: Lilian Date: Tue, 28 Feb 2023 11:39:39 +0100 Subject: [PATCH] add clientID --- backend/api/database/room/crud.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/api/database/room/crud.py b/backend/api/database/room/crud.py index d714f77..f6514a9 100644 --- a/backend/api/database/room/crud.py +++ b/backend/api/database/room/crud.py @@ -16,6 +16,7 @@ from database.room.models import Anonymous, Challenge, Challenges, CorrigedGener TmpCorrection, Waiter, MemberRead, CorrigedData, CorrectionData, Challenger from services.auth import get_current_user_optional from services.database import generate_unique_code +from uuid import UUID, uuid4 def create_room_db(*, room: RoomCreate, user: User | None = None, username: str | None = None, db: Session): @@ -178,7 +179,7 @@ def create_anonymous_member(username: str, room: Room, db: Session): return None reconnect_code = generate_unique_code( Anonymous, s=db, field_name="reconnect_code") - anonymous = Anonymous(username=username, reconnect_code=reconnect_code) + anonymous = Anonymous(username=username, reconnect_code=reconnect_code, clientId=uuid4()) member_id = generate_unique_code(Member, s=db) member = Member(room=room, anonymous=anonymous, id_code=member_id) db.add(member) @@ -787,9 +788,11 @@ def get_room(room_id, db: Session = Depends(get_session)): def get_member_dep(room: Room = Depends(get_room), user: User = Depends(get_current_user_optional), clientId: str | None = Query(default=None), db: Session = Depends(get_session)): + if user is None and clientId is None: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Not authenticated") + member = None if user is not None: member = get_member_from_user(user.id, room.id, db) elif clientId is not None: