Ejemplo n.º 1
0
def auth(request):
    """We dont need a full oauth setup just a username."""

    service = get_model_instance(request.user, PACKAGE_NAME)
    if service and request.method == 'POST':
        username = request.POST['username']

        if username:
            user_feed = get_url('http://feeds.delicious.com/v2/json/%s' % (username,))

            if username:
                # check the username is valid
                if user_feed[0]['d'] == '404 Not Found':
                    messages.error(request, 'Unable to find username "%s", please try again' % (username,))
                else:
                    if not service.auth:
                        auth_handler = Auth()
                    else:
                        auth_handler = service.auth
                    auth_handler.username = username
                    auth_handler.save()
                    if not service.auth:
                        service.auth = auth_handler
    
                    service.setup = True
                    service.public = True
                    service.save()
        else:
            messages.error(request, 'Please enter a Delicious username')

    return redirect(settings_redirect(request))
Ejemplo n.º 2
0
def auth(request):
    """We dont need a full oauth setup just a username.
    """

    # http://flickr.com/services/auth/?api_key=[api_key]&perms=[perms]&api_sig=[api_sig]

    service = get_model_instance(request.user, PACKAGE_NAME)

    if service and request.method == "POST":
        username = request.POST["username"]

        if username:
            # Talk to flickr to get a flickr ID 1234567@N0 style
            url = (
                "http://api.flickr.com/services/rest/?method=flickr.people.findByUsername&api_key=%s&username=%s&format=json&nojsoncallback=1"
                % (service.app.auth_settings["api_key"], username)
            )

            http_requester = httplib2.Http()
            resp, content = http_requester.request(url, "GET")

            if resp["status"] == "200":
                json = simplejson.loads(content)

                # Parse the request and check we have got back flickr id
                if json["stat"] == "ok":
                    userid = json["user"]["id"]

                    if not service.auth:
                        auth_handler = Auth()
                    else:
                        auth_handler = service.auth
                    auth_handler.username = username
                    auth_handler.secret = userid
                    auth_handler.save()
                    if not service.auth:
                        service.auth = auth_handler

                    service.setup = True
                    service.public = True
                    service.save()
                else:
                    messages.error(
                        request, "Unable to validate your username with Flickr, please check your username and retry."
                    )
        else:
            messages.error(request, "Please enter a Flickr username")
    return redirect(settings_redirect(request))
Ejemplo n.º 3
0
def auth(request):
    """We dont need a full oauth setup just a username.
    """
    service = get_model_instance(request.user, PACKAGE_NAME)
    if service and request.method == 'POST':
        username = request.POST['username']

        if username:
            # Fetch the page and try to find the reader id
            url = "http://www.google.com/reader/shared/%s" % (username,)
            links = SoupStrainer('link')
            h = httplib2.Http()
            resp, content = h.request(url, "GET")
            parsed_links = [tag for tag in soup(str(content), parseOnlyThese=links)]

            if parsed_links:
                try:
                    user_id = parsed_links[2].attrs[2][1].split('%2F')[1]

                    if not service.auth:
                        auth_handler = Auth()
                    else:
                        auth_handler = service.auth
                    auth_handler.username = username
                    auth_handler.secret = user_id
                    auth_handler.save()
                    if not service.auth:
                        service.auth = auth_handler

                    service.setup = True
                    service.public = True
                    service.save()
                except:
                    messages.error(
                        request,
                        'Unable to find Google Reader account with username "%s"' % (username,)
                    )
            else:
                messages.error(
                    request,
                    'Unable to find Google Reader account with username "%s"' % (username,)
                )
        else:
            messages.error(request, "Please enter a Google Reader username")

    return redirect(settings_redirect(request))
Ejemplo n.º 4
0
def auth(request):
    """We dont need a full oauth setup just a username.
    """
    service = get_model_instance(request.user, PACKAGE_NAME)
    if service and request.method == 'POST':
        username = request.POST['username']

        if username:
            user_feed = get_url('http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=%s&api_key=%s&format=json' % (
                                      username, service.app.auth_settings['api_key']))
            #user_feed = get_data(
                #service,
                #'http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=%s&api_key=%s&format=json'  % (
                    #username,
                    #service.app.auth_settings['api_key']
                #),
                #disable_oauth=True
            #)

            # check we have a valid username
            if user_feed.has_key('error'):
                messages.error(
                    request,
                    'Unable to validate your username "%s" with Last.fm, please check your username and retry.' % (
                    username,
                    )
                )
                return redirect(settings_redirect(request))
            
            if not service.auth:
                auth_handler = Auth()
            else:
                auth_handler = service.auth
            auth_handler.username = username
            auth_handler.save()
            if not service.auth:
                service.auth = auth_handler

            service.setup = True
            service.public = True
            service.save()

        else:
            messages.error(request, 'Please enter a Last.fm username')

    return redirect(settings_redirect(request))
Ejemplo n.º 5
0
def auth(request):
    """We dont need a full oauth setup just a username.
    """

    service = get_model_instance(request.user, PACKAGE)
    if service and request.method == 'POST':
        username = request.POST['username']

        if username:
            user_feed = get_data(
                service,
                'https://api.github.com/users/%s' % (username),
                disable_oauth=True
            )

            if user_feed.has_key('message') and user_feed['message'] == "Not Found":
                messages.error(request,
                               'Unable to validate your username with github, please check your username and retry.')
                return redirect(settings_redirect(request))
            
            if not service.auth:
                auth_handler = Auth()
            else:
                auth_handler = service.auth

            auth_handler.username = username
            auth_handler.save()

            if not service.auth:
                service.auth = auth_handler

            service.setup = True
            service.public = True
            service.save()
            
        else:
            messages.error(request, 'Please enter a github username')

    return redirect(settings_redirect(request))