SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit d41708f6 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

forbid invalid characters in username

parent 563c8430
No related branches found
No related tags found
No related merge requests found
...@@ -256,9 +256,16 @@ class RegistrationForm(forms.Form): ...@@ -256,9 +256,16 @@ class RegistrationForm(forms.Form):
return self.cleaned_data.get("password_verif", "") return self.cleaned_data.get("password_verif", "")
def clean_username(self): def clean_username(self):
if User.objects.filter(username=self.cleaned_data["username"]).exists(): # Username should not contain spaces or special characters
username = self.cleaned_data.get("username", "")
if re.search(r"[^a-zA-Z0-9._@\-+]", username):
raise forms.ValidationError(
"Your username may only contain letters, numbers, and any of the following: . _ @ - +"
)
if User.objects.filter(username=username).exists():
self.add_error("username", "This username is already in use") self.add_error("username", "This username is already in use")
return self.cleaned_data.get("username", "") return username
def clean_email(self): def clean_email(self):
if User.objects.filter(email=self.cleaned_data["email"]).exists(): if User.objects.filter(email=self.cleaned_data["email"]).exists():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment