]> git.openstreetmap.org Git - osqa.git/commitdiff
OSQA-684, improved logic during Facebook oauth2 authentication when dealing with...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sat, 2 Jul 2011 17:06:15 +0000 (17:06 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sat, 2 Jul 2011 17:06:15 +0000 (17:06 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1096 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum_modules/facebookauth/authentication.py
forum_modules/facebookauth/templates/button.html

index 308c18cf45afbca502154e17b43105a2b202e765..cc34fb5efed1bec27dbecaa7e3fb6bff24b54624 100644 (file)
@@ -47,9 +47,26 @@ class FacebookAuthConsumer(AuthenticationConsumer):
         # Communicate with the access token to the Facebook oauth interface.
         json = load_json(urlopen('https://graph.facebook.com/me?access_token=%s' % parsed_fbs['access_token'][0]))
 
+        first_name = smart_unicode(json['first_name'])
+        last_name = smart_unicode(json['last_name'])
+        full_name = '%s %s' % (first_name, last_name)
+
+        # There is a limit in the Django user model for the username length (no more than 30 characaters)
+        if len(full_name) <= 30:
+            username = full_name
+        # If the full name is too long use only the first
+        elif len(first_name) <= 30:
+            username = first_name
+        # If it's also that long -- only the last
+        elif len(last_name) <= 30:
+            username = last_name
+        # If the real name of the user is indeed that weird, let him choose something on his own =)
+        else:
+            username = ''
+
         # Return the user data.
         return {
-            'username': '%s %s' % (smart_unicode(json['first_name']), smart_unicode(json['last_name'])),
+            'username': username,
             'email': smart_unicode(json['email']),
         }
 
index ba03a30e88f58a2cf9cabb20c47dfa9642807015..db61aa2ea4ce0ed355ff3eda2d93dbc50e3c841d 100644 (file)
@@ -20,7 +20,7 @@
                     } else {\r
                       // user cancelled login\r
                     }\r
-                });\r
+                }, {perms:'email'});\r
             }\r
         });\r
     }\r