]> git.parisson.com Git - django-social-auth.git/commitdiff
Move UUID max length to settings. Closes gh-62
authorMatías Aguirre <matiasaguirre@gmail.com>
Wed, 4 May 2011 18:21:32 +0000 (15:21 -0300)
committerMatías Aguirre <matiasaguirre@gmail.com>
Wed, 4 May 2011 18:21:39 +0000 (15:21 -0300)
README.rst
doc/configuration.rst
social_auth/backends/__init__.py

index cb3e37dcbf60d5f35a61f96d33b631c7a2be0031..c06566876b0da4dbded46ddaa5bb4f072f994aa4 100644 (file)
@@ -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::
index 5330fe5a95e7107776bf6677c7af9ce3e0afbe9c..62489722433e70713cdc424a621424affe833cf9 100644 (file)
@@ -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::
index 76d3dc715f67fed391c05486234383998f45aad3..4eb1f15953dffa66b35cbddc109b5bf584dc1994 100644 (file)
@@ -65,8 +65,6 @@ USERNAME = 'username'
 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):
@@ -192,9 +190,10 @@ class SocialAuthBackend(ModelBackend):
                 # 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