Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
2 parents feb5ea0 + 3ac4b9d commit e7ac5f0bc1f9b1c4bedd765971345e3ea017e523 @krvss krvss committed Dec 21, 2011
Showing with 51 additions and 29 deletions.
  1. +7 −0 README.rst
  2. +2 −2 doc/conf.py
  3. +7 −0 doc/configuration.rst
  4. +2 −3 social_auth/backends/facebook.py
  5. +33 −24 social_auth/views.py
View
7 README.rst
@@ -319,6 +319,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
View
4 doc/conf.py
@@ -48,9 +48,9 @@
# built documents.
#
# The short X.Y version.
-version = '0.3.8'
+version = '0.6.0'
# The full version, including alpha/beta/rc tags.
-release = '0.3.8'
+release = '0.6.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
View
7 doc/configuration.rst
@@ -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
View
5 social_auth/backends/facebook.py
@@ -51,7 +51,6 @@ def get_user_details(self, response):
'last_name': response.get('last_name', '')}
-
class FacebookAuth(BaseOAuth2):
"""Facebook OAuth2 support"""
AUTH_BACKEND = FacebookBackend
@@ -75,9 +74,9 @@ def user_data(self, access_token):
sanitize_log_data(access_token),
extra=dict(data=data))
except ValueError:
- params.update({'access_token': sanitize_log_data(access_token)})
+ extra = {'access_token': sanitize_log_data(access_token)}
logger.error('Could not load user data from Facebook.',
- exc_info=True, extra=dict(data=params))
+ exc_info=True, extra=extra)
return data
def auth_complete(self, *args, **kwargs):
View
57 social_auth/views.py
@@ -29,7 +29,9 @@
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',
@@ -148,29 +150,36 @@ def auth_process(request, backend):
def complete_process(request, backend, *args, **kwargs):
"""Authentication complete process"""
user = auth_complete(request, backend, *args, **kwargs)
-
- 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 \
- request.session.pop(REDIRECT_FIELD_NAME, '') or \
- DEFAULT_REDIRECT
+ redirect_value = request.session.pop(REDIRECT_FIELD_NAME, '')
+
+ 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)

0 comments on commit e7ac5f0

Please sign in to comment.