Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
omab committed May 18, 2011
2 parents 0d2bf0c + 664cfef commit 0cb5437
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
27 changes: 23 additions & 4 deletions README.rst
Expand Up @@ -199,7 +199,10 @@ Configuration

in case your user layout needs to purify username on some weird way.

Final user name will have an integer suffix in case it's already taken.
Final user name will have a random UUID-generated suffix in case it's already
taken. The UUID token max length can be changed with the setting::

SOCIAL_AUTH_UUID_LENGTH = 16

- Backends will store extra values from response by default, set this to False
to avoid such behavior::
Expand Down Expand Up @@ -249,9 +252,10 @@ Configuration

SOCIAL_AUTH_CREATE_USERS = False

Also, it's possible to associate user accounts that share the same email
address if the user entry is unique (that means that if the email is not used
by more than one account). This behavior is disabled by default unless::
It is also possible to associate multiple user accounts with a single email
address as long as the rest of the user data is unique. Set value as True
to enable, otherwise set as False to disable.
This behavior is disabled by default (false) unless specifically set::

SOCIAL_AUTH_ASSOCIATE_BY_MAIL = True

Expand Down Expand Up @@ -496,6 +500,20 @@ credentials in the following way::
TEST_GOOGLE_USER = 'testing_account@gmail.com'
TEST_GOOGLE_PASSWORD = 'password_for_testing_account'


-------------
Miscellaneous
-------------

South_ users should add this rule to enable migrations::
try:
import south
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^social_auth\.fields\.JSONField"])
except:
pass


----
Bugs
----
Expand Down Expand Up @@ -597,3 +615,4 @@ Base work is copyrighted by:
.. _mattucf: https://github.com/mattucf
.. _Quard: https://github.com/Quard
.. _micrypt: https://github.com/micrypt
.. _South: http://south.aeracode.org/
5 changes: 4 additions & 1 deletion doc/configuration.rst
Expand Up @@ -110,7 +110,10 @@ Configuration

in case your user layout needs to purify username on some weird way.

Final user name will have an integer suffix in case it's already taken.
Final user name will have a random UUID-generated suffix in case it's already
taken. The UUID token max length can be changed with the setting::

SOCIAL_AUTH_UUID_LENGTH = 16

- Backends will store extra values from response by default, set this to False
to avoid such behavior::
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Expand Up @@ -19,6 +19,7 @@ Contents:
signals
contributions
testing
miscellaneous
bugs

Indices and tables
Expand Down
13 changes: 13 additions & 0 deletions doc/miscellaneous.rst
@@ -0,0 +1,13 @@
Miscellaneous
=============

South_ users should add this rule to enable migrations::
try:
import south
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^social_auth\.fields\.JSONField"])
except:
pass


.. _South: http://south.aeracode.org/
9 changes: 4 additions & 5 deletions social_auth/backends/__init__.py
Expand Up @@ -65,8 +65,6 @@
User = UserSocialAuth._meta.get_field('user').rel.to
# username field max length
USERNAME_MAX_LENGTH = User._meta.get_field(USERNAME).max_length
# uuid hex characters to keep while generating unique usernames
UUID_MAX_LENGTH = 16

# a few settings values
def _setting(name, default=None):
Expand Down Expand Up @@ -192,9 +190,10 @@ def get_random_username():
# breaking the field max_length value, this reduces the
# uniqueness, but it's less likely to happen repetitions than
# increasing an index.
if len(username) + UUID_MAX_LENGTH > USERNAME_MAX_LENGTH:
username = username[:USERNAME_MAX_LENGTH - UUID_MAX_LENGTH]
name = username + uuid4().get_hex()[:UUID_MAX_LENGTH]
uuid_length = getattr(settings, 'SOCIAL_AUTH_UUID_LENGTH', 16)
if len(username) + uuid_length > USERNAME_MAX_LENGTH:
username = username[:USERNAME_MAX_LENGTH - uuid_length]
name = username + uuid4().get_hex()[:uuid_length]

return final_username

Expand Down
6 changes: 4 additions & 2 deletions social_auth/views.py
Expand Up @@ -47,9 +47,11 @@ def complete_process(request, backend):
login(request, user)
if getattr(settings, 'SOCIAL_AUTH_SESSION_EXPIRATION', True):
# Set session expiration date if present and not disabled by
# setting
# setting. Use last social-auth instance for current provider,
# users can associate several accounts with a same provider.
backend_name = backend.AUTH_BACKEND.name
social_user = user.social_auth.get(provider=backend_name)
social_user = user.social_auth.filter(provider=backend_name) \
.order_by('-id')[0]
if social_user.expiration_delta():
request.session.set_expiry(social_user.expiration_delta())
url = request.session.pop(REDIRECT_FIELD_NAME, '') or DEFAULT_REDIRECT
Expand Down

0 comments on commit 0cb5437

Please sign in to comment.