[Fixed]-How to make allauth accept only gmail addresses belonging to a certain institute?

1👍

As far as I know, there isn’t a direct way to do this in django-allauth. The best bet is to listen for the user_signed_up signal and disable an account that does not have the required email address format.

from allauth.account.signals import user_signed_up
from django.dispatch import receiver

@receiver(user_signed_up)
def after_user_signed_up(request, user):
    if user.email.endswith('pilani.bits-pilani.ac.in'):
         # do something for valid accounts
    else :
         user.is_active = False
         user.save()
         # raise SomeException

If you have more than one address pattern, you will need multiple if statements or possibly create a model for the allowed email address patterns.

👤e4c5

0👍

There is no direct way to do it. But certainly there are few indirect ways. You can check using email header. From here you can get basic info about the email. You can store ip address and filter using that for a particular domain.

Leave a comment