Exemplo n.º 1
0
def login(request,
          redirect_to="invitations_contacts"
          ):  # @@@ redirect_to should not be hard-coded here
    ybbauth = ybrowserauth.YBrowserAuth(request.muaccount.yahoo_app_id,
                                        request.muaccount.yahoo_secret)
    yahoo_login = ybbauth.getAuthURL(appd=reverse(redirect_to))
    return HttpResponseRedirect(yahoo_login)
Exemplo n.º 2
0
def login(request,
          redirect_to="/invitations/contacts"
          ):  # @@@ redirect_to should not be hard-coded here
    ybbauth = ybrowserauth.YBrowserAuth(settings.BBAUTH_APP_ID,
                                        settings.BBAUTH_SHARED_SECRET)
    yahoo_login = ybbauth.getAuthURL(appd=redirect_to)
    return HttpResponseRedirect(yahoo_login)
Exemplo n.º 3
0
def handler(req):
    form = util.FieldStorage(req, keep_blank_values=1)
    ts = form.get("ts", None)
    sig = form.get("sig", None)
    token = form.get("token", None)
    userhash = form.get("userhash", None)
    appdata = form.get("appdata", None)

    # Instantiate the class
    cptr = ybrowserauth.YBrowserAuth(APPID, SECRET, ts, sig, token, userhash,
                                     appdata)

    if token == None:
        # If no token is found, create the authentication URL and display it
        req.content_type = "text/html"
        outstuff = cptr.getAuthURL('someappdata', 1)
        req.send_http_header()
        req.write('<html><body><h1>Test Yahoo! Mail API Using BBauth</h1><h2>')

        req.write(
            '<a href="' + outstuff +
            '">Click here to authorize access to your Y! Mail account</a>')

        req.write('</h2></body></html>')
    else:
        # If a token is found, it must be Yahoo!'s bbauth coming back as the
        # "success" URL. So, we validate the signature and do all the work
        req.content_type = "text/html"
        req.send_http_header()
        req.write('<html><body>')
        request_uri = req.parsed_uri[6] + '?' + req.parsed_uri[7]
        cptr.validate_sig(ts, sig, request_uri)
        req.write('<h2>BBauth Login Successful</h2>')
        req.write('Userhash is: ' + cptr.userhash + '<br />')

        req.write('Appdata is: ' + cptr.appdata + '<br />')
        client = cptr.makeJSONRPCcall('ListFolders', [{}])
        req.write('Timeout is: ' + cptr.timeout + '<br />')
        req.write('WSSID is: ' + cptr.WSSID + '<br />')
        req.write('Cookie is: ' + cptr.cookie + '<br />')
        req.write('Token is: ' + cptr.token + '<br /><br />')
        req.write(
            'Web Service call succeeded. Here are your mail folders: <br /><br /> '
        )
        for k in client['result']['folder']:
            if k['folderInfo']['name'] == '@B@Bulk':
                k['folderInfo']['name'] = 'Spam'
            req.write('<b>' + k['folderInfo']['name'] + ' </b> ' + ' msgs: ' +
                      str(k['total']) + ' unread: ' + str(k['unread']) +
                      ' total bytes: ' + str(k['size']) + '<br />')
        req.write('</body></html>')
    return apache.OK
Exemplo n.º 4
0
def success(request):
    if "appid" in request.GET:
        ybbauth = ybrowserauth.YBrowserAuth(settings.BBAUTH_APP_ID,
                                            settings.BBAUTH_SHARED_SECRET)
        ts = request.GET["ts"]
        sig = request.GET["sig"]
        appdata = request.GET["appdata"]
        REQUEST_URI = request.path + "?" + request.META['QUERY_STRING']
        ybbauth.validate_sig(ts, sig, REQUEST_URI)
        # add token to session for now
        request.session['bbauth_token'] = request.GET["token"]
        return HttpResponseRedirect(appdata)
    else:
        pass  # @@@
Exemplo n.º 5
0
def success(request):
    if "appid" in request.GET:
        ybbauth = ybrowserauth.YBrowserAuth(request.muaccount.yahoo_app_id,
                                            request.muaccount.yahoo_secret)
        ts = request.GET["ts"]
        sig = request.GET["sig"]
        appdata = request.GET["appdata"]
        REQUEST_URI = request.path + "?" + request.META['QUERY_STRING']
        #ybbauth.validate_sig(ts, sig, REQUEST_URI)
        # add token to session for now
        request.session['bbauth_token'] = request.GET["token"]
        return HttpResponseRedirect(appdata)
    else:
        pass  # @@@
Exemplo n.º 6
0
def import_yahoo(bbauth_token, user):
    """
    Uses the given BBAuth token to retrieve a Yahoo Address Book and
    import the entries with an email address into the contacts of the
    given user.
    
    Returns a tuple of (number imported, total number of entries).
    """

    ybbauth = ybrowserauth.YBrowserAuth(settings.BBAUTH_APP_ID,
                                        settings.BBAUTH_SHARED_SECRET)
    ybbauth.token = bbauth_token
    address_book_json = ybbauth.makeAuthWSgetCall(
        "http://address.yahooapis.com/v1/searchContacts?format=json&email.present=1&fields=name,email"
    )
    address_book = json.loads(address_book_json)

    total = 0
    imported = 0

    for contact in address_book["contacts"]:
        total += 1
        email = contact['fields'][0]['data']
        try:
            first_name = contact['fields'][1]['first']
        except (KeyError, IndexError):
            first_name = None
        try:
            last_name = contact['fields'][1]['last']
        except (KeyError, IndexError):
            last_name = None
        if first_name and last_name:
            name = first_name + " " + last_name
        elif first_name:
            name = first_name
        elif last_name:
            name = last_name
        else:
            name = None
        try:
            Contact.objects.get(user=user, email=email)
        except Contact.DoesNotExist:
            Contact(user=user, name=name, email=email).save()
            imported += 1

    return imported, total
Exemplo n.º 7
0
def handler(req):
    form = util.FieldStorage(req, keep_blank_values=1)
    ts = form.get("ts",None)
    sig = form.get("sig",None)
    token = form.get("token",None)
    userhash = form.get("userhash", None)
    appdata = form.get("appdata", None)

    # Instantiate the class    
    cptr = ybrowserauth.YBrowserAuth(APPID, SECRET, ts, sig, token, userhash, appdata)

    if token == None:
        # If no token is found, create the authentication URL and display it
        req.content_type = "text/html"
        outstuff = cptr.getAuthURL('someappdata', 1)
        req.send_http_header()
        req.write('<html><body><h1>Test Yahoo! Photos Web Services Using BBauth</h1><h2>')
        req.write('<a href="' + outstuff + '">Click here to authorize access to your Y! Photos account</a>')
        req.write('</h2></body></html>')
    else:
        # If a token is found, it must be Yahoo!'s bbauth coming back as the
        # "success" URL. So, we validate the signature and do all the work
        req.content_type = "text/html"
        req.send_http_header()
        req.write('<html><body>')
        request_uri = req.parsed_uri[6]+ '?' + req.parsed_uri[7]
        cptr.validate_sig(ts, sig, request_uri)
        req.write('<h2>BBauth login successful</h2>')
        req.write('Userhash is: ' + cptr.userhash + '<br />')
        req.write('Appdata is: ' + cptr.appdata + '<br />')
        xml = cptr.makeAuthWSgetCall('http://photos.yahooapis.com/V3.0/listAlbums?')
        req.write('Timeout is: ' + cptr.timeout + '<br />');
        req.write('WSSID is: ' + cptr.WSSID + '<br />');
        req.write('Cookie is: ' + cptr.cookie + '<br />');
        req.write('Token is: ' + cptr.token + '<br /><br />');
        req.write('Web Service call succeeded. XML response is: <br /><br /> ' + saxutils.escape(xml))
        req.write('</body></html>')
    return apache.OK