BenG
BenG

Reputation: 411

Django social auth check for email ending

have one question, how to check email ending via django social auth? For example I want that to my site could connect peoples who have email with @example.com ending.

Upvotes: 0

Views: 177

Answers (2)

omab
omab

Reputation: 3701

Add a pipeline entry that does the check, something like this should do the trick:

def check_email(details, *args, **kwargs):
    email = details['email']
    if not email.endswith('@example.com'):
        return HttpResponseRedirect('/invalid-email')

Put that before the create_user entry and. Take into account that some providers don't return the email (like Twitter).

Upvotes: 2

emispowder
emispowder

Reputation: 1797

If you are only using the google backend you can use the GOOGLE_WHITE_LISTED_DOMAINS setting.

Set it to a list of domains to restrict users to.

GOOGLE_WHITE_LISTED_DOMAINS = ['somedomain.com', 'anotherdomain.com']

More info here:

http://django-social-auth.readthedocs.org/en/latest/backends/google.html

Upvotes: 1

Related Questions