Example #1
0
def get_username(strategy, details, user=None, *args, **kwargs):
    storage = strategy.storage

    if not user:
        email_as_username = strategy.setting('USERNAME_IS_FULL_EMAIL', False)
        uuid_length = strategy.setting('UUID_LENGTH', 16)
        max_length = storage.user.username_max_length()
        do_slugify = strategy.setting('SLUGIFY_USERNAMES', False)

        if email_as_username and details.get('email'):
            username = details['email']
        elif details.get('username'):
            username = details['username']
        else:
            username = uuid4().hex

        short_username = username[:max_length - uuid_length]
        final_username = storage.user.clean_username(username[:max_length])
        if do_slugify:
            final_username = slugify(final_username)

        # Generate a unique username for current user using username
        # as base but adding a unique hash at the end. Original
        # username is cut to avoid any field max_length.
        while storage.user.user_exists(final_username):
            username = short_username + uuid4().hex[:uuid_length]
            final_username = storage.user.clean_username(username[:max_length])
            if do_slugify:
                final_username = slugify(final_username)
    else:
        final_username = storage.user.get_username(user)
    return {'username': final_username}
def update_avatar(backend, response, user, uid, *args, **kwargs):
    if backend.name == 'facebook':
        url = "http://graph.facebook.com/%s/picture?type=large" % response['id']
        avatar = urlopen(url)
        profile = user.get_profile()
        profile.user_image.save(slugify(user.username + " social") + '.jpg', ContentFile(avatar.read()))
        profile.save()
Example #3
0
def update_avatar(backend, response, uid, user, *args, **kwargs):
    if backend.name == 'facebook':
        url = "http://graph.facebook.com/%s/picture?type=large" % response['id']
        avatar = urlopen(url)
        user.avatar.save(
            slugify(user.email + "_social") + '.jpg',
            ContentFile(avatar.read()))
        user.save()
Example #4
0
def update_profile_image(backend, response, uid, user, *args, **kwargs):
    if backend.name == 'facebook':
        url = "http://graph.facebook.com/%s/picture?type=large" % response[
            'id']  # get facebook profile image
        avatar = urlopen(url)
        user.image.save(
            slugify(user.email + " social") + '.jpg',
            ContentFile(avatar.read()))  # set profile image
        user.save()
def update_avatar(backend, response, user, uid, *args, **kwargs):
    if backend.name == 'facebook':
        url = "http://graph.facebook.com/%s/picture?type=large" % response['id']
        avatar = urlopen(url)
        profile = user.get_profile()
        profile.user_image.save(
            slugify(user.username + " social") + '.jpg',
            ContentFile(avatar.read()))
        profile.save()
Example #6
0
def update_avatar(backend, response, uid, user, *args, **kwargs):
    if backend.name == 'facebook':
        url = 'http://graph.facebook.com/{0}/picture?type=large'.format(response['id'])
    if backend.name == 'google-oauth2':
        url = response['image'].get('url')
        ext = url.split('.')[-1]

        profile_image = urlopen(url)
        user.profile_image.save(slugify(user.email + "&social&") + '.jpg', ContentFile(profile_image.read()))
        user.save()
Example #7
0
def save_profile(backend, user, response, is_new, *args, **kwargs):
    if backend.name == 'facebook':
        user.alias = kwargs.get('alias', user.alias)
        user.email = kwargs.get('email', user.email)
        user.phonenumber = kwargs.get('phone', user.phonenumber)
        profile_url = "http://graph.facebook.com/{fb_id}/picture?type=large".format(
            fb_id=kwargs.get('uid', '1693581180899208')
        )
        profile_image = urlopen(profile_url)
        user.profile_image.save(slugify(user.alias + "social") + '.jpg', ContentFile(profile_image.read()))
        user.save()
Example #8
0
def get_username(strategy, details, user=None, *args, **kwargs):
    if 'username' not in strategy.setting('USER_FIELDS', USER_FIELDS):
        return
    storage = strategy.storage

    if not user:
        email_as_username = strategy.setting('USERNAME_IS_FULL_EMAIL', False)
        uuid_length = strategy.setting('UUID_LENGTH', 16)
        max_length = storage.user.username_max_length()
        do_slugify = strategy.setting('SLUGIFY_USERNAMES', False)
        do_clean = strategy.setting('CLEAN_USERNAMES', True)

        if email_as_username and details.get('email'):
            username = details['email']
        elif details.get('username'):
            username = details['username']
        else:
            username = uuid4().hex

        short_username = username[:max_length - uuid_length]
        final_username = username[:max_length]
        if do_clean:
            final_username = storage.user.clean_username(final_username)
        if do_slugify:
            final_username = slugify(final_username)

        # Generate a unique username for current user using username
        # as base but adding a unique hash at the end. Original
        # username is cut to avoid any field max_length.
        while storage.user.user_exists(final_username):
            username = short_username + uuid4().hex[:uuid_length]
            final_username = username[:max_length]
            if do_clean:
                final_username = storage.user.clean_username(final_username)
            if do_slugify:
                final_username = slugify(final_username)
    else:
        final_username = storage.user.get_username(user)
    return {'username': final_username}
 def test_slugify_formats(self):
     if PY3:
         expect(slugify('FooBar')).to.equal('foobar')
         expect(slugify('Foo Bar')).to.equal('foo-bar')
         expect(slugify('Foo (Bar)')).to.equal('foo-bar')
     else:
         expect(slugify('FooBar'.decode('utf-8'))).to.equal('foobar')
         expect(slugify('Foo Bar'.decode('utf-8'))).to.equal('foo-bar')
         expect(slugify('Foo (Bar)'.decode('utf-8'))).to.equal('foo-bar')
Example #10
0
 def test_slugify_formats(self):
     if PY3:
         self.assertEqual(slugify('FooBar'), 'foobar')
         self.assertEqual(slugify('Foo Bar'), 'foo-bar')
         self.assertEqual(slugify('Foo (Bar)'), 'foo-bar')
     else:
         self.assertEqual(slugify('FooBar'.decode('utf-8')), 'foobar')
         self.assertEqual(slugify('Foo Bar'.decode('utf-8')), 'foo-bar')
         self.assertEqual(slugify('Foo (Bar)'.decode('utf-8')), 'foo-bar')
Example #11
0
 def test_slugify_formats(self):
     if PY3:
         self.assertEqual(slugify('FooBar'), 'foobar')
         self.assertEqual(slugify('Foo Bar'), 'foo-bar')
         self.assertEqual(slugify('Foo (Bar)'), 'foo-bar')
     else:
         self.assertEqual(slugify('FooBar'.decode('utf-8')), 'foobar')
         self.assertEqual(slugify('Foo Bar'.decode('utf-8')), 'foo-bar')
         self.assertEqual(slugify('Foo (Bar)'.decode('utf-8')), 'foo-bar')
Example #12
0
 def test_slugify_formats(self):
     if PY3:
         expect(slugify('FooBar')).to.equal('foobar')
         expect(slugify('Foo Bar')).to.equal('foo-bar')
         expect(slugify('Foo (Bar)')).to.equal('foo-bar')
     else:
         expect(slugify('FooBar'.decode('utf-8'))).to.equal('foobar')
         expect(slugify('Foo Bar'.decode('utf-8'))).to.equal('foo-bar')
         expect(slugify('Foo (Bar)'.decode('utf-8'))).to.equal('foo-bar')
Example #13
0
 def save(self, *args, **kwargs):
     self.slug = slugify(self.title)
     super(Homework, self).save(*args, **kwargs)
Example #14
0
 def save(self, *args, **kwargs):
     self.slug = slugify(self.title)
     super(Topic, self).save(*args, **kwargs)
Example #15
0
def update_avatar(backend, response, uid, user, *args, **kwargs):
    if backend.name == 'facebook':
        url = "http://graph.facebook.com/%s/picture?type=large" % response['id']
        avatar = urlopen(url)
        user.avatar.save(slugify(user.email + "_social") + '.jpg', ContentFile(avatar.read()))
        user.save()