]> git.openstreetmap.org Git - osqa.git/blobdiff - forum_modules/facebookauth/authentication.py
OSQA-605, store user logins in a separate action, this helps to easily retrieve the...
[osqa.git] / forum_modules / facebookauth / authentication.py
index 308c18cf45afbca502154e17b43105a2b202e765..4e9a44ac3255db9086393cf037806a9278bcd10a 100644 (file)
@@ -47,10 +47,33 @@ 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 = ''
+
+        # Check whether the length if the email is greater than 75, if it is -- just replace the email
+        # with a blank string variable, otherwise we're going to have trouble with the Django model.
+        email = smart_unicode(json['email'])
+        if len(email) > 75:
+            email = ''
+
         # Return the user data.
         return {
-            'username': '%s %s' % (smart_unicode(json['first_name']), smart_unicode(json['last_name'])),
-            'email': smart_unicode(json['email']),
+            'username': username,
+            'email': email,
         }
 
 class FacebookAuthContext(ConsumerTemplateContext):
@@ -59,6 +82,6 @@ class FacebookAuthContext(ConsumerTemplateContext):
     weight = 100
     human_name = 'Facebook'
     code_template = 'modules/facebookauth/button.html'
-    extra_css = ["http://www.facebook.com/css/connect/connect_button.css"]
+    extra_css = []
 
     API_KEY = settings.FB_API_KEY
\ No newline at end of file