Beispiel #1
0
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
Beispiel #2
0
def get_username(backend, strategy, details, user=None, *args, **kwargs):

    if 'username' not in backend.setting('USER_FIELDS', USER_FIELDS):
        return
    storage = strategy.storage

    if not user:
        max_length = storage.user.username_max_length()
        do_slugify = backend.setting('SLUGIFY_USERNAMES', False)
        do_clean = backend.setting('CLEAN_USERNAMES', True)

        if do_clean:
            clean_func = storage.user.clean_username
        else:
            clean_func = lambda val: val

        if details.get('username'):
            username = details['username']
        else:
            username = uuid4().hex

        final_username = make_social_username(clean_func(username[:max_length - 2]))

    else:
        final_username = storage.user.get_username(user)

    return {'username': final_username}
Beispiel #3
0
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