From: Steven Cummings Date: Mon, 25 Jun 2012 04:07:46 +0000 (-0500) Subject: Replace raw ORM query for User by email with new models module method X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=c7eba3f68d0cf703dca97724a0bac16e9e6d81a9;p=django-social-auth.git Replace raw ORM query for User by email with new models module method --- diff --git a/social_auth/backends/pipeline/associate.py b/social_auth/backends/pipeline/associate.py index fd7c850..225844b 100644 --- a/social_auth/backends/pipeline/associate.py +++ b/social_auth/backends/pipeline/associate.py @@ -1,5 +1,5 @@ from social_auth.utils import setting -from social_auth.models import User +from social_auth.models import get_user_by_email from social_auth.backends.pipeline import warn_setting from social_auth.backends.exceptions import AuthException @@ -15,7 +15,7 @@ def associate_by_email(details, *args, **kwargs): # only if it's a single object. AuthException is raised if multiple # objects are returned try: - return {'user': User.objects.get(email=email)} + return {'user': get_user_by_email(email=email)} except User.MultipleObjectsReturned: raise AuthException(kwargs['backend'], 'Not unique email address.') except User.DoesNotExist: diff --git a/social_auth/django_models.py b/social_auth/django_models.py index ed37b0d..c10ded8 100644 --- a/social_auth/django_models.py +++ b/social_auth/django_models.py @@ -47,6 +47,10 @@ def get_user(user_id): return None +def get_user_by_email(email): + return User.objects.get(email=email) + + def get_social_auth_for_user(user): return user.social_auth.all() diff --git a/social_auth/mongoengine_models.py b/social_auth/mongoengine_models.py index 6a2a27d..7de8010 100644 --- a/social_auth/mongoengine_models.py +++ b/social_auth/mongoengine_models.py @@ -55,6 +55,10 @@ def get_user(user_id): return None +def get_user_by_email(email): + return User.objects.get(email=email) + + def get_social_auth_for_user(user): return UserSocialAuth.objects(user=user)