0

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

Nikhil Khandelwal
  • 198
  • 1
  • 2
  • 12

2 Answers2

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
  • 52,766
  • 11
  • 101
  • 134
  • well i am just confused abt where exactly to include this code. – Nikhil Khandelwal Feb 01 '17 at 17:21
  • usual place for signals handlers is in views.py, but it can also go in models.py too. For more info if needed http://stackoverflow.com/questions/40746137/post-save-signal-isnt-called/40883331#40883331 – e4c5 Feb 01 '17 at 17:33
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.

Community
  • 1
  • 1
kawadhiya21
  • 2,458
  • 21
  • 34