Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
Created January 25, 2012 20:52
Show Gist options
  • Save hgdeoro/1678650 to your computer and use it in GitHub Desktop.
Save hgdeoro/1678650 to your computer and use it in GitHub Desktop.
Parche para django_opendi_auth v0.4, para devolver usuario de Django asociado al EMAIL reportado por OpenId
index 58478ec..31e2833 100644
--- a/src/django_openid_auth/auth.py
+++ b/src/django_openid_auth/auth.py
@@ -30,6 +30,9 @@
__metaclass__ = type
+import logging
+import pprint
+
from django.conf import settings
from django.contrib.auth.models import User, Group
from openid.consumer.consumer import SUCCESS
@@ -79,6 +82,28 @@ class OpenIDBackend:
user = user_openid.user
if user is None:
+ details = self._extract_user_details(openid_response)
+ # details = {
+ # 'first_name': u'Fist Name',
+ # 'last_name': u'Last Name',
+ # 'nickname': None,
+ # 'email': u'[email protected]'
+ # }
+
+ if 'email' in details:
+ try:
+ user = User.objects.get(email=details['email'])
+ if not user.is_active:
+ logging.error("Se encontro el usuario %d asociado a email '%s', "
+ "pero el usuario no esta 'activo'.", user.id, details['email'])
+ user = None
+ except User.DoesNotExist:
+ pass
+ else:
+ logging.error("Se encontro entrada 'email' en detalles: %s",
+ pprint.pformat(details))
+
+ if user is None:
return None
if getattr(settings, 'OPENID_UPDATE_DETAILS_FROM_SREG', False):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment