From: Steven Van Bael Date: Fri, 18 Nov 2011 08:53:44 +0000 (+0100) Subject: Override get_user() in SocialAuthBackend so it supports returning users from a custom... X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=cca9ad912bb15e49e06ad57f784d9b476be26d59;p=django-social-auth.git Override get_user() in SocialAuthBackend so it supports returning users from a custom user model --- diff --git a/social_auth/backends/__init__.py b/social_auth/backends/__init__.py index 649bdd1..182b3f5 100644 --- a/social_auth/backends/__init__.py +++ b/social_auth/backends/__init__.py @@ -26,6 +26,7 @@ from openid.extensions import sreg, ax from oauth2 import Consumer as OAuthConsumer, Token, Request as OAuthRequest, \ SignatureMethod_HMAC_SHA1 +from django.db import models from django.conf import settings from django.contrib.auth import authenticate from django.contrib.auth.backends import ModelBackend @@ -38,6 +39,12 @@ from social_auth.store import DjangoOpenIDStore from social_auth.backends.exceptions import StopPipeline +if getattr(settings, 'SOCIAL_AUTH_USER_MODEL', None): + User = models.get_model(*settings.SOCIAL_AUTH_USER_MODEL.rsplit('.', 1)) +else: + from django.contrib.auth.models import User + + # OpenID configuration OLD_AX_ATTRS = [ ('http://schema.openid.net/contact/email', 'old_email'), @@ -156,6 +163,12 @@ class SocialAuthBackend(ModelBackend): """ raise NotImplementedError('Implement in subclass') + def get_user(self, user_id): + """Return user with given ID from the User model used by this backend""" + try: + return User.objects.get(pk=user_id) + except User.DoesNotExist: + return None class OAuthBackend(SocialAuthBackend): """OAuth authentication backend base class.