简体   繁体   中英

How to make allauth accept only gmail addresses belonging to a certain institute?

Example:-

qwe123@ pilani.bits-pilani.ac.in

I think i just need to check if the "template ending" is present in the email address or not but the problem is where to check it in the allauth package

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM