Esempio n. 1
0
 def __init__(
         self, host, path, port=80, params={}, headers={},
         timeout=61, username=None, password=None, 
         min_tcp_ip_delay=0.25, max_tcp_ip_delay=16,
         min_http_delay=10, max_http_delay=240
     ):
     """Store config and build the connection headers.
     """
     
     self.host = host
     self.port = port
     self.path = path
     self.body = unicode_urlencode(params)
     if username and password:
         headers['Authorization'] = generate_auth_header(username, password)
     header_lines = [
         'POST %s HTTP/1.1' % self.path,
         'Host: %s' % self.host,
         'Content-Length: %s' % len(self.body),
         'Content-Type: application/x-www-form-urlencoded'
     ]
     header_lines.extend([
             '%s: %s' % (k, v) for k, v in headers.iteritems()
         ] + ['', '']
     )
     self.headers = '\r\n'.join(header_lines)
     self.timeout = timeout
     self.min_tcp_ip_delay = min_tcp_ip_delay
     self.max_tcp_ip_delay = max_tcp_ip_delay
     self.min_http_delay = min_http_delay
     self.max_http_delay = max_http_delay
     self.id = generate_hash()
Esempio n. 2
0
def logout_page():
    """
    Web Page to Logout User, then Redirect them to Index Page.
    """
    auth_header = generate_auth_header(request)
    logout_url = auth_endpoint_url+'logout'
    response = post(logout_url, headers=auth_header, verify=verify_cert)
    if response.status_code == 200:
        print 'logout works!'

    logout_user()

    return redirect(url_for('pubswh:index'))
Esempio n. 3
0
 def __init__(
         self, ready_list_id, num_items, url, headers={}, username=None, password=None,
         item_parser=None, min_sleep=2, max_sleep=3600
     ):
     self.ready_key = '%s.%s' % (DATA_KEY, ready_list_id)
     self.num_items = num_items
     self.url = url
     if username and password:
         headers['Authorization'] = generate_auth_header(username, password)
     self.headers = headers
     self.item_parser = item_parser
     self.delay = min_sleep
     self.min_sleep = min_sleep
     self.max_sleep = max_sleep
def restricted_page(index_id):
    """
    web page which is restricted and requires the user to be logged in.
    """

    # generate the auth header from the request
    auth_header = generate_auth_header(request)
    # build the url to call the endpoint
    published_status = get(pub_url + 'publication/' + index_id,
                           params={'mimetype': 'json'}, verify=verify_cert).status_code
    # go out to mypubs and get the record
    response = get(preview_endpoint_url+index_id+'/preview', headers=auth_header, verify=verify_cert,
                   params={'mimetype': 'json'})
    print "preview status code: ", response.status_code
    if response.status_code == 200:
        record = response.json()
        pubdata = munge_pubdata_for_display(record, replace_pubs_with_pubs_test, supersedes_url, json_ld_id_base_url)
        return render_template("preview.html", indexID=index_id, pubdata=pubdata)
    # if the publication has been published (so it is out of mypubs) redirect to the right URL
    elif response.status_code == 404 and published_status == 200:
        return redirect(url_for('publication', indexId=index_id))
    elif response.status_code == 404 and published_status == 404:
        return render_template('404.html')