From 755f320eac5d2d461c19073459218fccc52db874 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mat=C3=ADas=20Aguirre?= Date: Fri, 3 Jun 2011 22:57:49 -0300 Subject: [PATCH] Add redirect url for newly created users. Closes gh-47 --- README.rst | 8 ++++++-- doc/configuration.rst | 4 ++++ social_auth/backends/__init__.py | 1 + social_auth/views.py | 9 ++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index cf26886..1f24abf 100644 --- a/README.rst +++ b/README.rst @@ -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:: diff --git a/doc/configuration.rst b/doc/configuration.rst index c7645c8..c3e5f87 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -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:: diff --git a/social_auth/backends/__init__.py b/social_auth/backends/__init__.py index d7b4a2d..ce3046d 100644 --- a/social_auth/backends/__init__.py +++ b/social_auth/backends/__init__.py @@ -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: diff --git a/social_auth/views.py b/social_auth/views.py index 026be13..62a7238 100644 --- a/social_auth/views.py +++ b/social_auth/views.py @@ -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 -- 2.39.5