Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override clean_email() method in Django-allauth

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.

like image 541
Ryu_hayabusa Avatar asked Sep 05 '25 03:09

Ryu_hayabusa


1 Answers

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.

like image 87
pennersr Avatar answered Sep 07 '25 21:09

pennersr