]> git.parisson.com Git - django-social-auth.git/commitdiff
Difference active/inactive users on complete process. Closes #197
authorMatías Aguirre <matiasaguirre@gmail.com>
Sun, 18 Dec 2011 22:03:00 +0000 (20:03 -0200)
committerMatías Aguirre <matiasaguirre@gmail.com>
Sun, 18 Dec 2011 22:03:00 +0000 (20:03 -0200)
README.rst
doc/configuration.rst
social_auth/views.py

index 3a038d3e2111ad2e61e69d9cb045b2022a769c50..5626fc65b4e12ec45b4e55d5bc336840cc6e4506 100644 (file)
@@ -316,6 +316,13 @@ Configuration
 
       SOCIAL_AUTH_SANITIZE_REDIRECTS = False
 
+- Inactive users can be redirected to a different page if this setting is
+  defined::
+
+      SOCIAL_AUTH_INACTIVE_USER_URL = '...'
+
+  Defaults to ``LOGIN_ERROR_URL``.
+
 
 -------
 Signals
index 801c73fe652518bec98772bf69fcfeffd7f1b6ee..5b2e02fb82bfc072d45e7592975656d04f4d9c74 100644 (file)
@@ -213,6 +213,13 @@ Configuration
 
       SOCIAL_AUTH_SANITIZE_REDIRECTS = False
 
+- Inactive users can be redirected to a different page if this setting is
+  defined::
+
+      SOCIAL_AUTH_INACTIVE_USER_URL = '...'
+
+  Defaults to ``LOGIN_ERROR_URL``.
+
 
 .. _Model Manager: http://docs.djangoproject.com/en/dev/topics/db/managers/#managers
 .. _Login URL: http://docs.djangoproject.com/en/dev/ref/settings/?from=olddocs#login-url
index a906576fe139be1a9241b098986237b64d077c43..d1f049eea40c180d40e75c453744c012b1715f97 100644 (file)
@@ -29,7 +29,9 @@ NEW_USER_REDIRECT = setting('SOCIAL_AUTH_NEW_USER_REDIRECT_URL')
 NEW_ASSOCIATION_REDIRECT = setting('SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL')
 DISCONNECT_REDIRECT_URL = setting('SOCIAL_AUTH_DISCONNECT_REDIRECT_URL')
 LOGIN_ERROR_URL = setting('LOGIN_ERROR_URL', settings.LOGIN_URL)
-COMPLETE_URL_NAME = setting('SOCIAL_AUTH_COMPLETE_URL_NAME', 'socialauth_complete')
+INACTIVE_USER_URL = setting('SOCIAL_AUTH_INACTIVE_USER_URL', LOGIN_ERROR_URL)
+COMPLETE_URL_NAME = setting('SOCIAL_AUTH_COMPLETE_URL_NAME',
+                            'socialauth_complete')
 ASSOCIATE_URL_NAME = setting('SOCIAL_AUTH_ASSOCIATE_URL_NAME',
                               'socialauth_associate_complete')
 SOCIAL_AUTH_LAST_LOGIN = setting('SOCIAL_AUTH_LAST_LOGIN',
@@ -150,28 +152,34 @@ def complete_process(request, backend, *args, **kwargs):
     user = auth_complete(request, backend, *args, **kwargs)
     redirect_value = request.session.pop(REDIRECT_FIELD_NAME, '')
 
-    if user and getattr(user, 'is_active', True):
-        login(request, user)
-        # user.social_user is the used UserSocialAuth instance defined
-        # in authenticate process
-        social_user = user.social_user
-
-        if SESSION_EXPIRATION :
-            # Set session expiration date if present and not disabled by
-            # setting. Use last social-auth instance for current provider,
-            # users can associate several accounts with a same provider.
-            if social_user.expiration_delta():
-                request.session.set_expiry(social_user.expiration_delta())
-
-        # store last login backend name in session
-        request.session[SOCIAL_AUTH_LAST_LOGIN] = social_user.provider
-
-        # Remove possible redirect URL from session, if this is a new account,
-        # send him to the new-users-page if defined.
-        url = NEW_USER_REDIRECT if NEW_USER_REDIRECT and \
-                                   getattr(user, 'is_new', False) else \
-              redirect_value or \
-              DEFAULT_REDIRECT
+    if isinstance(user, HttpResponse):
+        return user
+
+    if user:
+        if getattr(user, 'is_active', True):
+            login(request, user)
+            # user.social_user is the used UserSocialAuth instance defined
+            # in authenticate process
+            social_user = user.social_user
+
+            if SESSION_EXPIRATION :
+                # Set session expiration date if present and not disabled by
+                # setting. Use last social-auth instance for current provider,
+                # users can associate several accounts with a same provider.
+                if social_user.expiration_delta():
+                    request.session.set_expiry(social_user.expiration_delta())
+
+            # store last login backend name in session
+            request.session[SOCIAL_AUTH_LAST_LOGIN] = social_user.provider
+
+            # Remove possible redirect URL from session, if this is a new
+            # account, send him to the new-users-page if defined.
+            url = NEW_USER_REDIRECT if NEW_USER_REDIRECT and \
+                                       getattr(user, 'is_new', False) else \
+                  redirect_value or \
+                  DEFAULT_REDIRECT
+        else:
+            url = INACTIVE_USER_URL or LOGIN_ERROR_URL
     else:
         if ERROR_MESSAGE:
             messages.error(request, ERROR_MESSAGE)