From b713dc6b02bd8c9343bd4f2b79aeb8dc3996968f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mat=C3=ADas=20Aguirre?= Date: Tue, 23 Nov 2010 03:45:58 -0200 Subject: [PATCH] Doc fix and added missing check --- README.rst | 2 +- social_auth/models.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index ed364da..d03e320 100644 --- a/README.rst +++ b/README.rst @@ -108,7 +108,7 @@ and the methods:: is_authenticated() AttributeError will be raised in case of any of these is -missing, also the following are recommended but notenforced:: +missing, also the following are recommended but not enforced:: first_name = CharField(...) last_name = CharField(...) diff --git a/social_auth/models.py b/social_auth/models.py index 325f6dd..c09137a 100644 --- a/social_auth/models.py +++ b/social_auth/models.py @@ -3,15 +3,26 @@ from django.db import models from django.conf import settings # If User class is overrided, it must provide the following fields: +# # username = CharField() # email = EmailField() # password = CharField() +# is_active = BooleanField() +# +# and methods: +# +# def is_authenticated(): +# ... MANDATORY_FIELDS = ('username', 'email', 'password', 'last_login') +MANDATORY_METHODS = ('is_authenticated',) try: # try to import User model override and validate needed fields User = models.get_model(*settings.SOCIAL_AUTH_USER_MODEL.split('.')) if not all(User._meta.get_field(name) for name in MANDATORY_FIELDS): raise AttributeError, 'Some mandatory field missing' + if not all(callable(getattr(User, name, None)) + for name in MANDATORY_METHODS): + raise AttributeError, 'Some mandatory methods missing' except: # fail silently and fallback to auth.User on any error from django.contrib.auth.models import User -- 2.39.5