Commit aef211b9ad52f33f55cbb6199fdd2cf85db2672d
Committed by
Sergio Oliveira
1 parent
cfee3a09
Exists in
master
and in
13 other branches
Validated blank space in username field
Validated a case where the user was able to insert blank space in username field in the Register step Signed-off-by: Carlos Oliveira <carlospecter@gmail.com> Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Showing
1 changed file
with
13 additions
and
6 deletions
Show diff stats
colab/accounts/forms.py
| @@ -32,11 +32,6 @@ class UserForm(forms.ModelForm): | @@ -32,11 +32,6 @@ class UserForm(forms.ModelForm): | ||
| 32 | # Forces username to be lowercase always | 32 | # Forces username to be lowercase always |
| 33 | widget=forms.TextInput(attrs={'style' : 'text-transform: lowercase;'}), | 33 | widget=forms.TextInput(attrs={'style' : 'text-transform: lowercase;'}), |
| 34 | ) | 34 | ) |
| 35 | - email = forms.EmailField( | ||
| 36 | - | ||
| 37 | - # Forces email to be a read-only field | ||
| 38 | - widget=forms.TextInput(attrs={'readonly': 'readonly'}) | ||
| 39 | - ) | ||
| 40 | required = ('first_name', 'last_name', 'email', 'username') | 35 | required = ('first_name', 'last_name', 'email', 'username') |
| 41 | 36 | ||
| 42 | class Meta: | 37 | class Meta: |
| @@ -53,8 +48,20 @@ class UserForm(forms.ModelForm): | @@ -53,8 +48,20 @@ class UserForm(forms.ModelForm): | ||
| 53 | field.required = True | 48 | field.required = True |
| 54 | 49 | ||
| 55 | 50 | ||
| 56 | - | ||
| 57 | class UserCreationForm(UserForm): | 51 | class UserCreationForm(UserForm): |
| 52 | + email = forms.EmailField( | ||
| 53 | + | ||
| 54 | + # Forces email to be a read-only field | ||
| 55 | + widget=forms.TextInput(attrs={'readonly': 'readonly'}) | ||
| 56 | + ) | ||
| 57 | + | ||
| 58 | + def clean_username(self): | ||
| 59 | + username = self.cleaned_data['username'] | ||
| 60 | + username = username.strip() | ||
| 61 | + if len(username) is 0: | ||
| 62 | + raise forms.ValidationError('This field should not be blank.') | ||
| 63 | + return username | ||
| 64 | + | ||
| 58 | class Meta: | 65 | class Meta: |
| 59 | model = User | 66 | model = User |
| 60 | fields = ('first_name', 'last_name', 'email', 'username') | 67 | fields = ('first_name', 'last_name', 'email', 'username') |