Cleanup and simplify

This commit is contained in:
Lilian 2023-02-28 12:12:38 +01:00 committed by Kilton937342
parent 71ec645ced
commit fff0618d27
2 changed files with 13 additions and 7 deletions

View File

@ -29,12 +29,16 @@ def create_room_db(*, room: RoomCreate, user: User | None = None, username: str
db.add(member) db.add(member)
db.commit() db.commit()
db.refresh(member) db.refresh(member)
if username is not None: if username is not None:
reconnect_code = generate_unique_code( # reconnect_code = generate_unique_code(
Anonymous, s=db, field_name='reconnect_code') # Anonymous, s=db, field_name='reconnect_code')
anonymous = Anonymous(username=username, reconnect_code=reconnect_code) # anonymous = Anonymous(username=username, reconnect_code=reconnect_code)
member = Member(anonymous=anonymous, room=room_obj, # member = Member(anonymous=anonymous, room=room_obj,
is_admin=True, id_code=member_id) # is_admin=True, id_code=member_id)
member = create_anonymous_member(username, room_obj, db)
member.is_admin = True
db.add(member) db.add(member)
db.commit() db.commit()
db.refresh(member) db.refresh(member)
@ -163,7 +167,8 @@ def disconnect_member(member: Member, db: Session):
def validate_username(username: str, room: Room, db: Session = Depends(get_session)): def validate_username(username: str, room: Room, db: Session = Depends(get_session)):
if len(username) > 20: username = username.strip()
if 4 < len(username) > 15:
return None return None
members = select(Member.anonymous_id).where( members = select(Member.anonymous_id).where(
Member.room_id == room.id, Member.anonymous_id != None) Member.room_id == room.id, Member.anonymous_id != None)

View File

@ -169,7 +169,8 @@ class RoomConsumer(Consumer):
user=user, room=self.room, waiting=self.room.public is False, db=self.db) user=user, room=self.room, waiting=self.room.public is False, db=self.db)
elif username is not None: elif username is not None:
if len(username) < 4 or len(username) > 15: username = username.strip()
if 4 > len(username) > 15:
await self.send_error("Nom invalide (4-15 caractères)") await self.send_error("Nom invalide (4-15 caractères)")
return return