From c7eba3f68d0cf703dca97724a0bac16e9e6d81a9 Mon Sep 17 00:00:00 2001 From: Steven Cummings Date: Sun, 24 Jun 2012 23:07:46 -0500 Subject: [PATCH] Replace raw ORM query for User by email with new models module method --- social_auth/backends/pipeline/associate.py | 4 ++-- social_auth/django_models.py | 4 ++++ social_auth/mongoengine_models.py | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) 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) -- 2.39.5