How can i override the default clean_email()
method in allauth.account.forms.BaseSignupForm
.
I tried the following in Forms.py:
from allauth.account.forms import BaseSignupForm
class Extended_BaseSignupForm(BaseSignupForm):
def clean_email(self):
data = self.cleaned_data['email']
if "@gmail.com" not in data: # any check you need
raise forms.ValidationError("Must be a gmail address")
if app_settings.UNIQUE_EMAIL:
if data and email_address_exists(data):
raise forms.ValidationError \
(_("A user is registered with this e-mail address."))
return data
The purpose of overriding is to prevent users from registering with disposable email IDs.
This has been made easier in the upcoming version of allauth. You can simply override the clean_email
adapter method, over here:
https://github.com/pennersr/django-allauth/blob/4bb9e0170f37d8196bd0c4a78e83adb7b779c113/allauth/account/adapter.py#L175
Use the ACCOUNT_ADAPTER
setting to point to your custom adapter containing the overriden method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With