]> git.parisson.com Git - django-social-auth.git/commitdiff
Add redirect url for newly created users. Closes gh-47
authorMatías Aguirre <matiasaguirre@gmail.com>
Sat, 4 Jun 2011 01:57:49 +0000 (22:57 -0300)
committerMatías Aguirre <matiasaguirre@gmail.com>
Sat, 4 Jun 2011 01:57:49 +0000 (22:57 -0300)
README.rst
doc/configuration.rst
social_auth/backends/__init__.py
social_auth/views.py

index cf26886d1dbf8b25ddf36e5d31811d882cd94a49..1f24abf37d7829171264ddab105d14fc72d0cb8f 100644 (file)
@@ -10,9 +10,9 @@ implements a common interface to define new authentication providers from
 third parties.
 
 
------
+----
 Demo
------
+----
 There's a demo at http://social.matiasaguirre.net/.
 Note: It lacks some backends support at the moment.
 
@@ -157,6 +157,10 @@ Configuration
 
     SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/another-login-url/'
 
+  A different URL could be defined for newly registered users::
+
+    SOCIAL_AUTH_NEW_USER_REDIRECT_URL = '/new-users-login-url/'
+
   In case of authentication error, the message can be stored in session
   if the following setting is defined::
 
index c7645c807c3aab9250ffbd7a29a7bd76acccb052..c3e5f87eed2e9b2d58167710fcb57c829394ffc0 100644 (file)
@@ -67,6 +67,10 @@ Configuration
 
     SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/another-login-url/'
 
+  A different URL could be defined for newly registered users::
+
+    SOCIAL_AUTH_NEW_USER_REDIRECT_URL = '/new-users-login-url/'
+
   In case of authentication error, the message can be stored in session
   if the following setting is defined::
 
index d7b4a2de59bd09b6d99ae782426f44e69e5b7eff..ce3046d4f575bcecd948cceed2a94c65b3f8480c 100644 (file)
@@ -139,6 +139,7 @@ class SocialAuthBackend(ModelBackend):
 
         # Update user account data.
         self.update_user_details(user, response, details, is_new)
+        setattr(user, 'is_new', is_new)
 
         # Update extra_data storage, unless disabled by setting
         if LOAD_EXTRA_DATA:
index 026be13c4e228c436b27f81fdee20679abd66924..62a72384a1e4f01aa0ec61557065222c4c3b6b06 100644 (file)
@@ -13,6 +13,7 @@ from social_auth.utils import sanitize_redirect
 
 DEFAULT_REDIRECT = getattr(settings, 'SOCIAL_AUTH_LOGIN_REDIRECT_URL', '') or \
                    getattr(settings, 'LOGIN_REDIRECT_URL', '')
+NEW_USER_REDIRECT = getattr(settings, 'SOCIAL_AUTH_NEW_USER_REDIRECT_URL', '')
 SOCIAL_AUTH_LAST_LOGIN = getattr(settings, 'SOCIAL_AUTH_LAST_LOGIN',
                                  'social_auth_last_login_backend')
 
@@ -57,7 +58,13 @@ def complete_process(request, backend):
             social_user = user.social_user
             if social_user.expiration_delta():
                 request.session.set_expiry(social_user.expiration_delta())
-        url = request.session.pop(REDIRECT_FIELD_NAME, '') or DEFAULT_REDIRECT
+
+        url = request.session.pop(REDIRECT_FIELD_NAME, '')
+        if not url:
+            if NEW_USER_REDIRECT and getattr(user, 'is_new', False):
+                url = NEW_USER_REDIRECT
+            else:
+                url = DEFAULT_REDIRECT
 
         # store last login backend name in session
         request.session[SOCIAL_AUTH_LAST_LOGIN] = social_user.provider