diff --git a/src/apps/profiles/forms.py b/src/apps/profiles/forms.py index a959acb8d..c2b0b43cc 100644 --- a/src/apps/profiles/forms.py +++ b/src/apps/profiles/forms.py @@ -4,8 +4,22 @@ class SignUpForm(UserCreationForm): - email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.') + + email = forms.EmailField( + max_length=254, help_text="Required. Inform a valid email address." + ) + + def clean_username(self): + data = self.cleaned_data["username"] + if not data.islower(): + raise forms.ValidationError("Usernames should be in lowercase") + if not data.isalnum(): + raise forms.ValidationError( + "Usernames should not contain special characters." + ) + return data class Meta: + model = User - fields = ('username', 'email', 'password1', 'password2', ) + fields = ("username", "email", "password1", "password2")