Example #1
0
def get_user_authorization(request):
    """Redirects to the hyves page to ask for permission
    """
    from django.conf import settings

    from social.utils import get_genus

    genus = get_genus()

    token = genus.retrieve_request_token(
            settings.CONSUMER_METHODS,
            getattr(settings, 'HYVES_EXPIRATION_TYPE', 'default')
    )

    request.session['requesttoken_user'] = pickle.dumps(token)
    import sys
    try:
        site = Site.objects.get_current()

    except:
        print "Unexpected error:", sys.exc_info()[0]
        raise

    url = get_authorize_url(
    token,
    "http://" + site.domain + reverse('authorized_redirect')
    )

    return HttpResponseRedirect(url)
Example #2
0
def get_authorization_by_logintoken(request, logintoken):
    """Redirect for users who do have a logintoken (i.e. a hyvertysing page)
    """
    genus = get_genus()

    access_token = genus.retrieve_access_token_by_login(
        logintoken
    )

    access_token, created = UserAssociation.objects.get_or_create_from_token(
            access_token
        )

    user = authenticate(
        username=access_token.user.username,
        password=access_token.get_password())

    if not user:
        mail_admins(
            'authenticate failure for: %s ' % access_token.user.username,
            'Faulty password? or user does not exist')

    login(request, user)

    social_user_authenticated.send(
        sender=None,
        user=user,
        access_token=access_token)

    return HttpResponseRedirect(
            reverse('get_authorized') + \
                "?%s" % request.META['QUERY_STRING']
        )
Example #3
0
def index(request, show_more=False):
    """Retrieve the index... currently also does a small API call
    """

    if request.GET.get('logintoken'):
        return redirect(
            reverse(
                'social.views.get_authorization_by_logintoken',
                kwargs={
                    'logintoken': request.GET.get('logintoken')
                    }
            ) + "?%s" % request.META['QUERY_STRING']
        )
    context = {}

    if show_more:
        genus = get_genus()

        result = genus.do_method(
            "media.getPublic",
            {
                "sorttype": "mostrespect",
                'mediatype': 'image',
                'timespan': 'day'
            }
        )

        context.update({'media': result['media']})

    return render_to_response('social/index.html', context)
Example #4
0
    def _wrapped_view(request, *args, **kwargs):

        if request.session.get('requesttoken_user', False):

            kwargs.update(
                {
                    'requesttoken_user': pickle.loads(
                            request.session.get('requesttoken_user')
                        ),
                    'genus': get_genus()
                }
            )

            return view_func(request, *args, **kwargs)

        path = urlquote(request.get_full_path())
        tup = redirect_url, redirect_field_name, path

        return HttpResponseRedirect('%s?%s=%s' % tup)
Example #5
0
    def _wrapped_view(request, *args, **kwargs):

        if request.user.is_authenticated():
            try:
                access_token = UserAssociation.objects.select_related().get(
                        user=request.user
                    )
            except UserAssociation.DoesNotExist:
                access_token = None

            if access_token:
                kwargs.update(
                    {
                        'access_token': access_token,
                        'genus': get_genus()
                    }
                )

                return view_func(request, *args, **kwargs)

        path = urlquote(request.get_full_path())
        tup = redirect_url, redirect_field_name, path

        return HttpResponseRedirect('%s?%s=%s' % tup)
Example #6
0
def retrieve_friends(from_user=''):
    """Retrieve a list of friends and stores it in the cache
    (it's also returned).

    .. note::
      This method requires a valid access_token (UserAssociation instance).
    """

    from django.conf import settings

    user = User.objects.get(id=from_user)

    genus = get_genus()

    access_token = UserAssociation.objects.get(user=user)

    params = (
        {
            'sorttype': 'alphabetically',
            'ha_responsefields': 'profilepicture',
            'ha_resultsperpage': settings.HYVES_LIST_PAGE_SIZE,
            'ha_page': '1',
        }
    )

    method = 'users.getFriendsByLoggedinSorted'

    result = genus.do_method(method, params, access_token)

    users = result['user']

    total_pages = result['info']['totalpages']

    if result['info']['currentpage'] < total_pages:

        for i in range(2, total_pages + 1):
            params = (
                {
                    'sorttype': 'alphabetically',
                    'ha_responsefields': 'profilepicture',
                    'ha_resultsperpage': settings.HYVES_LIST_PAGE_SIZE,
                    'ha_page': i,
                }
            )

            params['ha_page'] = str(i)

            result = genus.do_method(method, params, access_token)

            users.extend(result['user'])

    user_info = []

    for user in users:
        temp_info = {
                'userid': user['userid'],
                'firstname': user['firstname'],
                'lastname': user['lastname'],
                'friendscount': user['friendscount'],
                'profilepicture': {
                    'icon_large': {
                        'src_medium':
                            user['profilepicture']['square_extralarge']['src'],
                        'src_small':
                            user['profilepicture']['square_large']['src'],
                    }
                }
            }

        if 'image' in user['profilepicture']:
            src = user['profilepicture']['image']['src']

        else:
            src = user['profilepicture']['icon_extralarge']

        temp_info['profilepicture']['src'] = src
        user_info.append(temp_info)

    return user_info