Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
krvss committed Dec 21, 2011
2 parents feb5ea0 + 3ac4b9d commit e7ac5f0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 29 deletions.
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions social_auth/backends/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
57 changes: 33 additions & 24 deletions social_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e7ac5f0

Please sign in to comment.