Skip to content

Commit

Permalink
Prevent duplicate character and team tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
freyamade committed Jan 20, 2022
1 parent 34107b8 commit e9f97f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion backend/api/models/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ def generate_token() -> str:
"""
Generate a token for a Character to use for verification
"""
return 'savageaim-' + ''.join(choice(CHARACTERS) for _ in range(RANDOM_CHARS))
code = 'savageaim-' + ''.join(choice(CHARACTERS) for _ in range(RANDOM_CHARS))
while Character.objects.filter(token=code).exists():
code = 'savageaim-' + ''.join(choice(CHARACTERS) for _ in range(RANDOM_CHARS))

return code
6 changes: 5 additions & 1 deletion backend/api/models/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ def generate_invite_code() -> str:
Generate a new invite code for a team
Can be used to regenerate the code later as needed
"""
return ''.join(choice(CHARS) for _ in range(CODE_LEN))
code = ''.join(choice(CHARS) for _ in range(CODE_LEN))
while Team.objects.filter(invite_code=code).exists():
code = ''.join(choice(CHARS) for _ in range(CODE_LEN))

return code

0 comments on commit e9f97f7

Please sign in to comment.