Cleanup and simplify
This commit is contained in:
parent
71ec645ced
commit
fff0618d27
@ -29,12 +29,16 @@ def create_room_db(*, room: RoomCreate, user: User | None = None, username: str
|
||||
db.add(member)
|
||||
db.commit()
|
||||
db.refresh(member)
|
||||
|
||||
if username is not None:
|
||||
reconnect_code = generate_unique_code(
|
||||
Anonymous, s=db, field_name='reconnect_code')
|
||||
anonymous = Anonymous(username=username, reconnect_code=reconnect_code)
|
||||
member = Member(anonymous=anonymous, room=room_obj,
|
||||
is_admin=True, id_code=member_id)
|
||||
# reconnect_code = generate_unique_code(
|
||||
# Anonymous, s=db, field_name='reconnect_code')
|
||||
# anonymous = Anonymous(username=username, reconnect_code=reconnect_code)
|
||||
# member = Member(anonymous=anonymous, room=room_obj,
|
||||
# is_admin=True, id_code=member_id)
|
||||
member = create_anonymous_member(username, room_obj, db)
|
||||
member.is_admin = True
|
||||
|
||||
db.add(member)
|
||||
db.commit()
|
||||
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)):
|
||||
if len(username) > 20:
|
||||
username = username.strip()
|
||||
if 4 < len(username) > 15:
|
||||
return None
|
||||
members = select(Member.anonymous_id).where(
|
||||
Member.room_id == room.id, Member.anonymous_id != None)
|
||||
|
@ -169,7 +169,8 @@ class RoomConsumer(Consumer):
|
||||
user=user, room=self.room, waiting=self.room.public is False, db=self.db)
|
||||
|
||||
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)")
|
||||
return
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user