diff --git a/README.rst b/README.rst index 18a32a7..d349af4 100644 --- a/README.rst +++ b/README.rst @@ -96,6 +96,9 @@ Optional settings:: # list of default group names to assign to new users GOOGLEAUTH_GROUPS = [] + # create new user if it doesn't exist, default True + GOOGLEAUTH_USER_CREATE = True + URL routes ~~~~~~~~~~ @@ -107,4 +110,4 @@ Add URL config:: ... ) -googleauth doesn't need to be mounted under */auth/*, it can go anywhere. Place it where you see fit for your specific app. \ No newline at end of file +googleauth doesn't need to be mounted under */auth/*, it can go anywhere. Place it where you see fit for your specific app. diff --git a/googleauth/backends.py b/googleauth/backends.py index 919868b..f27b616 100644 --- a/googleauth/backends.py +++ b/googleauth/backends.py @@ -5,6 +5,7 @@ IS_STAFF = getattr(settings, 'GOOGLEAUTH_IS_STAFF', False) GROUPS = getattr(settings, 'GOOGLEAUTH_GROUPS', tuple()) APPS_DOMAIN = getattr(settings, 'GOOGLEAUTH_APPS_DOMAIN', None) +USER_CREATE = getattr(settings, 'GOOGLEAUTH_USER_CREATE', True) class GoogleAuthBackend(object): @@ -29,6 +30,9 @@ def authenticate(self, identifier=None, attributes=None): except User.DoesNotExist: + if not USER_CREATE: + return None + user = User.objects.create(username=username, email=email) user.first_name = attributes.get('first_name') or '' user.last_name = attributes.get('last_name') or '' diff --git a/googleauth/urls.py b/googleauth/urls.py index 891da5e..3203157 100644 --- a/googleauth/urls.py +++ b/googleauth/urls.py @@ -1,4 +1,8 @@ -from django.conf.urls import * +try: + from django.conf.urls import url, patterns +except: + # django 1.3 + from django.conf.urls.defaults import url, patterns urlpatterns = patterns('', url(r'^login/$', 'googleauth.views.login', name='googleauth_login'),