Skip to content

Commit

Permalink
disallow claiming a purely numerical username
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Apr 9, 2024
1 parent 0bf4db7 commit 4edcdfe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions liberapay/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ def msg(self, _):
return _("The username '{0}' contains invalid characters.", self.username)


class UsernameIsPurelyNumerical(UsernameError):
def msg(self, _):
return _("The username '{0}' is purely numerical. This isn't allowed.")


class UsernameIsRestricted(UsernameError):
def msg(self, _):
return _("The username '{0}' is restricted.", self.username)
Expand Down
7 changes: 6 additions & 1 deletion liberapay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
UsernameContainsInvalidCharacters,
UsernameEndsWithForbiddenSuffix,
UsernameIsEmpty,
UsernameIsPurelyNumerical,
UsernameIsRestricted,
UsernameTooLong,
ValueTooLong,
Expand Down Expand Up @@ -2048,6 +2049,9 @@ def check_username(suggested):
if set(suggested) - ASCII_ALLOWED_IN_USERNAME:
raise UsernameContainsInvalidCharacters(suggested)

if suggested.isdigit():
raise UsernameIsPurelyNumerical(suggested)

if suggested[0] == '.':
raise UsernameBeginsWithRestrictedCharacter(suggested)

Expand All @@ -2059,7 +2063,8 @@ def check_username(suggested):
raise UsernameIsRestricted(suggested)

def change_username(self, suggested, cursor=None, recorder=None):
self.check_username(suggested)
if suggested != f'~{self.id}':
self.check_username(suggested)
recorder_id = getattr(recorder, 'id', None)

if suggested != self.username:
Expand Down

0 comments on commit 4edcdfe

Please sign in to comment.