diff options
| author | Magnus Hagander | 2025-07-02 20:20:52 +0000 |
|---|---|---|
| committer | Magnus Hagander | 2025-07-02 20:28:30 +0000 |
| commit | 7d33e398a6e421f7af8a46685a23d699e52b2df5 (patch) | |
| tree | 67fd9d27c6f7023c0361910e30c7d3b8d34660ef /pgweb | |
| parent | 0c8f2d7bca89aab19689a20daa5ab45d381e0c28 (diff) | |
Do full email validation in oauth signup form
These fields aren't editable anyway, but if we don't do the full
validation we will instead crash if for example the same account
creation form is submitted twice (happens surprisingly often). Now we
will instead show a validation error message.
Diffstat (limited to 'pgweb')
| -rw-r--r-- | pgweb/account/forms.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/pgweb/account/forms.py b/pgweb/account/forms.py index 31cd3741..fb3641b0 100644 --- a/pgweb/account/forms.py +++ b/pgweb/account/forms.py @@ -28,6 +28,18 @@ def _clean_username(username): raise forms.ValidationError("This username is already in use") +def _clean_email(email): + email = email.lower() + + if User.objects.filter(email=email).exists(): + raise forms.ValidationError("A user with this email address is already registered") + + if SecondaryEmail.objects.filter(email=email).exists(): + raise forms.ValidationError("This email address is already attached to a different user") + + return email + + # Override some error handling only in the default authentication form class PgwebAuthenticationForm(AuthenticationForm): def clean(self): @@ -91,15 +103,7 @@ class SignupForm(forms.Form): return _clean_username(self.cleaned_data['username']) def clean_email(self): - email = self.cleaned_data['email'].lower() - - if User.objects.filter(email=email).exists(): - raise forms.ValidationError("A user with this email address is already registered") - - if SecondaryEmail.objects.filter(email=email).exists(): - raise forms.ValidationError("This email address is already attached to a different user") - - return email + return _clean_email(self.cleaned_data['email']) class SignupOauthForm(forms.Form): @@ -122,7 +126,7 @@ class SignupOauthForm(forms.Form): return _clean_username(self.cleaned_data['username']) def clean_email(self): - return self.cleaned_data['email'].lower() + return _clean_email(self.cleaned_data['email']) class UserProfileForm(forms.ModelForm): |
