Пример #1
0
def twitter_authorization_redirection_end(request):
    integrator = TwitterIntegrator()
    if 'oauth_token' in request.GET and \
        'oauth_verifier' in request.GET:
        oauth_token = request.GET.get('oauth_token')
        oauth_verifier = request.GET.get('oauth_verifier')

        redirect_uri = integrator.get_full_registration_end_url()
        request_token_key = psv_get(request, 'twitter_oauth_request_token_key',
                                    None)
        request_token_secret = psv_get(request,
                                       'twitter_oauth_request_token_secret',
                                       None)

        access_token_dict = integrator.get_access_token_dict(
            redirect_uri, request_token_key, request_token_secret,
            oauth_verifier)

    else:
        access_token_dict = None
    if access_token_dict is not None:
        psv_set(request, 'twitter_access_token_key', access_token_dict['key'])
        psv_set(request, 'twitter_access_token_secret',
                access_token_dict['secret'])
        integrator.add_twitter_user_record(access_token_dict['key'],
                                           access_token_dict['secret'],
                                           request.user)
        return redirect('show_user_profile', request.user.id)

    # TODO: fix this, in case url returns without an oauth code, which
    # shouldn't happen anyway.
    return HttpResponseRedirect(integrator.get_registration_form_url())
Пример #2
0
def facebook_login_redirection_end(request):
    integrator = FacebookIntegrator()
    if 'code' in request.GET:
        code = request.GET.get('code')
        redirect_uri = integrator.get_full_login_end_url()
        access_token = integrator.get_access_token(redirect_uri, code)
    else:
        access_token = None
    print access_token
    if access_token is not None:
        psv_set(request,'facebook_access_token',access_token)
        # If a Django user associated with the current Facebook account
        # already exists and in that case simply start an authenticathed 
        # session and redirect to proper place depending on the presence 
        # or absence of some session values.
        user = integrator.get_user_by_facebook_user_id(access_token)
        if user:
            user.backend = settings.DEFAULT_AUTH_BACKEND
            login(request, user)    
            redirect_uri = get_redirect_uri(request)
            return HttpResponseRedirect(redirect_uri)
        else:
            #FIXME: Refactor this code to show this message without
            # using an extra view since only in this case that page
            # should be reached by the user.
            redirect_uri = reverse('facebook_login')
            return HttpResponseRedirect(redirect_uri)

    # Redirect to the default login URL if the process fails
    return HttpResponseRedirect(settings.LOGIN_URL)
Пример #3
0
def facebook_login_redirection_end(request):
    integrator = FacebookIntegrator()
    if 'code' in request.GET:
        code = request.GET.get('code')
        redirect_uri = integrator.get_full_login_end_url()
        access_token = integrator.get_access_token(redirect_uri, code)
    else:
        access_token = None
    print access_token
    if access_token is not None:
        psv_set(request, 'facebook_access_token', access_token)
        # If a Django user associated with the current Facebook account
        # already exists and in that case simply start an authenticathed
        # session and redirect to proper place depending on the presence
        # or absence of some session values.
        user = integrator.get_user_by_facebook_user_id(access_token)
        if user:
            user.backend = settings.DEFAULT_AUTH_BACKEND
            login(request, user)
            redirect_uri = get_redirect_uri(request)
            return HttpResponseRedirect(redirect_uri)
        else:
            #FIXME: Refactor this code to show this message without
            # using an extra view since only in this case that page
            # should be reached by the user.
            redirect_uri = reverse('facebook_login')
            return HttpResponseRedirect(redirect_uri)

    # Redirect to the default login URL if the process fails
    return HttpResponseRedirect(settings.LOGIN_URL)
Пример #4
0
def twitter_login_redirection_end(request):
    integrator = TwitterIntegrator()
    if 'oauth_token' in request.GET and \
       'oauth_verifier' in request.GET:
        oauth_token = request.GET.get('oauth_token')
        oauth_verifier = request.GET.get('oauth_verifier')
        redirect_uri = integrator.get_full_login_end_url()
        request_token_key = psv_get(
            request,
            'twitter_oauth_request_token_key',
            None
        )
        request_token_secret = psv_get(
            request,
            'twitter_oauth_request_token_secret',
            None
        )
        access_token_dict = integrator.get_access_token_dict(
            redirect_uri, 
            request_token_key,
            request_token_secret,
            oauth_verifier
        )
    else:
        access_token_dict = None
    if access_token_dict is not None:
        psv_set(
            request, 
            'twitter_access_token_key', 
            access_token_dict['key']
        )
        psv_set(
            request, 
            'twitter_access_token_secret', 
            access_token_dict['secret']
        )
        # If a Django user associated with the current Twitter account
        # already exists and in that case simply start an authenticathed 
        # session and redirect to proper place depending on the presence 
        # or absence of some session values.
        user = integrator.get_user_by_twitter_user_id(
            access_token_dict['key'],
            access_token_dict['secret']
        )
        if user:
            user.backend = settings.DEFAULT_AUTH_BACKEND
            login(request, user)    
            redirect_uri = get_redirect_uri(request)
            return HttpResponseRedirect(redirect_uri)
        else:
            #FIXME: Refactor this code to show this message without
            # using an extra view since only in this case that page
            # should be reached by the user.
            redirect_uri = reverse('twitter_login_register')
            return HttpResponseRedirect(redirect_uri)
    # Redirect to the default login URL if the process fails
    return HttpResponseRedirect(settings.LOGIN_URL)
Пример #5
0
def facebook_login(request):
    # Register expected optional parameters
    params = ('client_id', 'redirect_uri', )
    for p in params:
        v = request.GET.get(p, None)
        if v is not None:
            psv_set(request, 'login_' +p ,v)
    # Start authorization request
    integrator = FacebookIntegrator()
    redirect_uri = integrator.get_full_login_end_url()
    authorization_uri = integrator.create_login_url(redirect_uri)
    return HttpResponseRedirect(authorization_uri)
Пример #6
0
def twitter_login_authorization(request):
    # Register expected optional parameters
    params = (
        'client_id',
        'redirect_uri',
    )
    for p in params:
        v = request.GET.get(p, None)
        if v is not None:
            psv_set(request, 'login_' + p, v)
    # Start authorization request
    integrator = TwitterIntegrator()
    redirect_uri = integrator.get_full_login_end_url()
    authorization_uri = integrator.create_login_url(redirect_uri)
    return HttpResponseRedirect(authorization_uri)
Пример #7
0
def twitter_authorization_redirection_end(request):
    integrator = TwitterIntegrator()
    if 'oauth_token' in request.GET and \
        'oauth_verifier' in request.GET:
        oauth_token = request.GET.get('oauth_token')
        oauth_verifier = request.GET.get('oauth_verifier')
        
        redirect_uri = integrator.get_full_registration_end_url()
        request_token_key = psv_get(
            request,
            'twitter_oauth_request_token_key',
            None
        )
        request_token_secret = psv_get(
            request,
            'twitter_oauth_request_token_secret',
            None
        )

        access_token_dict = integrator.get_access_token_dict(
            redirect_uri, 
            request_token_key,
            request_token_secret,
            oauth_verifier
        )

    else:
        access_token_dict = None 
    if access_token_dict is not None:
        psv_set(
            request, 
            'twitter_access_token_key', 
            access_token_dict['key']
        )
        psv_set(
            request, 
            'twitter_access_token_secret', 
            access_token_dict['secret'])
        integrator.add_twitter_user_record(
            access_token_dict['key'],
            access_token_dict['secret'],
            request.user
        )
        return redirect('show_user_profile', request.user.id)
        
    # TODO: fix this, in case url returns without an oauth code, which
    # shouldn't happen anyway.
    return HttpResponseRedirect(integrator.get_registration_form_url())
Пример #8
0
def facebook_authorization_redirection_end(request):
    integrator = FacebookIntegrator()
    if 'code' in request.GET:
        code = request.GET.get('code')
        redirect_uri = integrator.get_full_registration_end_url()
        access_token = integrator.get_access_token(redirect_uri, code)
    else:
        access_token = None
    if access_token is not None:
        psv_set(request, 'facebook_access_token', access_token)
        integrator.add_facebook_user_record(access_token, request.user)
        return redirect('show_user_profile', request.user.id)

    psv_restore(request, temp_dict)
    # TODO: fix this, in case url returns without an oauth code, which
    # shouldn't happen anyway.
    return HttpResponseRedirect(integrator.get_registration_form_url())
Пример #9
0
def foursquare_authorization_redirection_end(request):
    integrator = FoursquareIntegrator()
    if 'code' in request.GET:
        code = request.GET.get('code')
        redirect_uri = integrator.get_full_registration_end_url()
        access_token = integrator.get_access_token(redirect_uri, code)
    else:
        access_token = None
    if access_token is not None:
        psv_set(request, 'foursquare_access_token', access_token)
        integrator.add_foursquare_user_record(access_token, request.user)
        return redirect('show_user_profile', request.user.id)

    psv_restore(request, temp_dict)
    # TODO: fix this, in case url returns without an oauth code, which
    # shouldn't happen anyway.
    return HttpResponseRedirect(integrator.get_registration_form_url())
Пример #10
0
def twitter_login_redirection_end(request):
    integrator = TwitterIntegrator()
    if 'oauth_token' in request.GET and \
       'oauth_verifier' in request.GET:
        oauth_token = request.GET.get('oauth_token')
        oauth_verifier = request.GET.get('oauth_verifier')
        redirect_uri = integrator.get_full_login_end_url()
        request_token_key = psv_get(request, 'twitter_oauth_request_token_key',
                                    None)
        request_token_secret = psv_get(request,
                                       'twitter_oauth_request_token_secret',
                                       None)
        access_token_dict = integrator.get_access_token_dict(
            redirect_uri, request_token_key, request_token_secret,
            oauth_verifier)
    else:
        access_token_dict = None
    if access_token_dict is not None:
        psv_set(request, 'twitter_access_token_key', access_token_dict['key'])
        psv_set(request, 'twitter_access_token_secret',
                access_token_dict['secret'])
        # If a Django user associated with the current Twitter account
        # already exists and in that case simply start an authenticathed
        # session and redirect to proper place depending on the presence
        # or absence of some session values.
        user = integrator.get_user_by_twitter_user_id(
            access_token_dict['key'], access_token_dict['secret'])
        if user:
            user.backend = settings.DEFAULT_AUTH_BACKEND
            login(request, user)
            redirect_uri = get_redirect_uri(request)
            return HttpResponseRedirect(redirect_uri)
        else:
            #FIXME: Refactor this code to show this message without
            # using an extra view since only in this case that page
            # should be reached by the user.
            redirect_uri = reverse('twitter_login_register')
            return HttpResponseRedirect(redirect_uri)
    # Redirect to the default login URL if the process fails
    return HttpResponseRedirect(settings.LOGIN_URL)
Пример #11
0
def twitter_authorization(request):
    # Register expected optional parameters
    params = (
        'client_id',
        'redirect_uri',
    )
    for p in params:
        v = request.GET.get(p, None)
        if v is not None:
            psv_set(request, 'registration_' + p, v)
    # Start authorization request
    integrator = TwitterIntegrator()
    redirect_uri = integrator.get_full_registration_end_url()
    authorization_uri = integrator.create_authorization_url(redirect_uri)
    # Set request token key and secret
    psv_set(request, 'twitter_oauth_request_token_key',
            integrator.get_request_token_key())
    psv_set(request, 'twitter_oauth_request_token_secret',
            integrator.get_request_token_secret())
    return HttpResponseRedirect(authorization_uri)
Пример #12
0
def twitter_authorization(request):
    # Register expected optional parameters
    params = ('client_id', 'redirect_uri', )
    for p in params:
        v = request.GET.get(p, None)
        if v is not None:
            psv_set(request, 'registration_' + p, v)
    # Start authorization request
    integrator = TwitterIntegrator()
    redirect_uri = integrator.get_full_registration_end_url()
    authorization_uri = integrator.create_authorization_url(redirect_uri)
    # Set request token key and secret
    psv_set(
        request, 
        'twitter_oauth_request_token_key', 
        integrator.get_request_token_key()
    )
    psv_set(
        request, 
        'twitter_oauth_request_token_secret', 
        integrator.get_request_token_secret()
    )
    return HttpResponseRedirect(authorization_uri)