[Answered ]-How to add email blacklist option in django-allauth?

1👍

First, you need to create a custom account adapter

# utils/adapter.py

from allauth.account.adapter import DefaultAccountAdapter
from django import forms
from django.conf import settings


class CustomAccountAdapter(DefaultAccountAdapter):
    def clean_email(self, email):
        if email in settings.ACCOUNT_EMAIL_BLACKLIST:
            raise forms.ValidationError(f"{email} has been blacklisted")
        return super().clean_email(email)

Then, change the ACCOUNT_ADAPTER settings value

# settings.py

ACCOUNT_ADAPTER = "utils.adapter.CustomAccountAdapter"
ACCOUNT_EMAIL_BLACKLIST = ["someemail.test.com"]
👤JPG

Leave a comment