From 33e3484ebacd4b5100c60514f8571e511dea5411 Mon Sep 17 00:00:00 2001 From: Steven Cummings Date: Sun, 24 Jun 2012 23:15:11 -0500 Subject: [PATCH] Replace user-or-id resolution with new models module method --- social_auth/backends/utils.py | 8 ++------ social_auth/django_models.py | 6 ++++++ social_auth/mongoengine_models.py | 6 ++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/social_auth/backends/utils.py b/social_auth/backends/utils.py index bd69bdc..566036c 100644 --- a/social_auth/backends/utils.py +++ b/social_auth/backends/utils.py @@ -4,17 +4,13 @@ from oauth2 import Consumer as OAuthConsumer, Token, Request as OAuthRequest, \ from django.utils import simplejson -from social_auth.models import User +from social_auth.models import resolve_user_or_id def consumer_oauth_url_request(backend, url, user_or_id, redirect_uri='/', json=True): """Builds and retrieves an OAuth signed response.""" - if isinstance(user_or_id, User): - user = user_or_id - else: - user = User.objects.get(pk=user_or_id) - + user = resolve_user_or_id(user_or_id) oauth_info = user.social_auth.filter(provider=backend.AUTH_BACKEND.name)[0] token = Token.from_string(oauth_info.tokens['access_token']) request = build_consumer_oauth_request(backend, token, url, redirect_uri) diff --git a/social_auth/django_models.py b/social_auth/django_models.py index c10ded8..f12a4f9 100644 --- a/social_auth/django_models.py +++ b/social_auth/django_models.py @@ -51,6 +51,12 @@ def get_user_by_email(email): return User.objects.get(email=email) +def resolve_user_or_id(user_or_id): + if isinstance(user_or_id, User): + return user_or_id + return User.objects.get(pk=user_or_id) + + 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 7de8010..59fc42e 100644 --- a/social_auth/mongoengine_models.py +++ b/social_auth/mongoengine_models.py @@ -59,6 +59,12 @@ def get_user_by_email(email): return User.objects.get(email=email) +def resolve_user_or_id(user_or_id): + if isinstance(user_or_id, User): + return user_or_id + return User.objects.get(pk=user_or_id) + + def get_social_auth_for_user(user): return UserSocialAuth.objects(user=user) -- 2.39.5