Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Feature/username regex #717

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openbook_auth/tests/views/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_invalid_username(self):
should return 400 if the username is not valid
"""
url = self._get_url()
invalid_usernames = ('joel<;<', '<>', ' shantanu space ', 'greater_than_30_characters_username_is_not_valid',)
invalid_usernames = ('joel<;<', '<>', ' shantanu space ', 'greater_than_30_characters_username_is_not_valid','.start_with_period','more_than__one_special_char','end_with_period.')
token = self._make_user_invite_token()
for username in invalid_usernames:
data = {
Expand Down
6 changes: 4 additions & 2 deletions openbook_auth/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@


def username_characters_validator(username):
if not re.match('^[a-zA-Z0-9_.]*$', username):
if not re.match("^[a-zA-Z0-9](?:[._]?[a-z-A-Z0-9])*$", username):
raise ValidationError(
_('Usernames can only contain alphanumeric characters, periods and underscores.'),
_(
'Usernames can only contain alphanumeric characters, periods and underscores. They must not begin or end with a period or underscore.'
)
)


Expand Down