def google_user_update(sender, user, response, details, **kwargs): profile_instance, created = DateaProfile.objects.get_or_create(user=user) uname = slugify(details['username']) if uname != user.username: user.username = make_social_username(details['username']) if not user.email: user.email = details['email'] if not profile_instance.full_name: if details['first_name'] != '' or details['last_name'] != '': profile_instance.full_name = details['first_name']+' '+details['last_name'] elif details['username'] != '': profile_instance.full_name = details['username'] # grabar imagen de avatar try: img = urlopen(response['picture']) if profile_instance.image_social == None: img_obj = DateaImage(user=user) img_obj.image.save(slugify(user.username + "_g") + '.jpg', ContentFile(img.read())) img_obj.save() profile_instance.image_social = img_obj else: profile_instance.image_social.image.save(slugify(user.username + "_g") + '.jpg', ContentFile(img.read())) profile_instance.image_social.save() except HTTPError: pass profile_instance.save() return True
def facebook_user_update(sender, user, response, details, **kwargs): profile_instance, created = DateaProfile.objects.get_or_create(user=user) f = open("/tmp/debug.txt", "w") f.write("details username: "******"\n") f.write("user username: "******"\n") f.close() uname = slugify(details['username']) if uname != user.username: user.username = make_social_username(details['username']) if not user.email: user.email = details['email'] if not profile_instance.full_name: if details['first_name'] != '' or details['last_name'] != '': profile_instance.full_name = details['first_name']+' '+details['last_name'] elif details['username'] != '': profile_instance.full_name = details['username'] # grabar imagen de avatar try: img_url = "http://graph.facebook.com/%s/picture?type=large" % response["id"] img = urlopen(img_url) if profile_instance.image_social == None: img_obj = DateaImage(user=user) img_obj.image.save(slugify(user.username + "_fb") + '.jpg', ContentFile(img.read())) img_obj.save() profile_instance.image_social = img_obj else: profile_instance.image_social.image.save(slugify(user.username + "_fb") + '.jpg', ContentFile(img.read())) profile_instance.image_social.save() except HTTPError: pass profile_instance.save() return True