예제 #1
0
파일: views.py 프로젝트: jxguan/CertChain
def certify_transcript_single(request):
  if request.method == 'POST':
    student_id = request.POST['student_id']
    payload = {
      'commitment': hashlib.sha256(os.urandom(8)).hexdigest(),
      'student_id': student_id,
      'recipient': request.POST['recipient'],
      'gpa': request.POST['gpa'],
      'date': request.POST['date']
    }
    # Be careful here; remember that changing the way the document
    # is formatted will create different hashes. We also eliminate
    # space b/w separators so that when we recreate the document
    # client-side, we get the same string representation for hashing.
    document = json.dumps(payload, sort_keys=True, separators=(',', ':'))
    resp = requests.post(create_rpc_url('/certify/Transcript/'+student_id),
      data=document)
    if resp.status_code == 200 and resp.text == 'OK':
      messages.success(request,\
        'The transcript has been submitted to the network for certification.')
    else:
      messages.error(request,\
        'An error occurred while processing your \
        certification request: ' + resp.text)
    return redirect(reverse('certchain:certify'))
  raise Http404
예제 #2
0
파일: views.py 프로젝트: jxguan/CertChain
def certify_transcript_batch(request):
  if request.method == 'POST':
    batch_csv = request.POST['batch_contents']
    documents = []
    for row in batch_csv.split('\n'):
      cols = row.split(',')
      if len(cols) == 4:
        doc = {
          'commitment': hashlib.sha256(os.urandom(8)).hexdigest(),
          'student_id': cols[0],
          'recipient': cols[1],
          'gpa': cols[2],
          'conferral_date': cols[3]
        }
        documents.append(json.dumps(doc, sort_keys=True, separators=(',', ':')))
    # Be careful here; remember that changing the way the document
    # is formatted will create different hashes. We also eliminate
    # space b/w separators so that when we recreate the document
    # client-side, we get the same string representation for hashing.
    payload = json.dumps(documents)
    resp = requests.post(create_rpc_url('/certify/Transcript'),
      data=payload)
    if resp.status_code == 200 and resp.text == 'OK':
      messages.success(request,\
        'The transcripts have been submitted to the network for certification.')
    else:
      messages.error(request,\
        'An error occurred while processing your \
        certification request: ' + resp.text)
    return redirect(reverse('certchain:certify'))
  raise Http404
예제 #3
0
파일: views.py 프로젝트: jxguan/CertChain
def overview(request):
  try:
    resp = requests.get(create_rpc_url('/network'))
    return render(request, 'certchain/overview.html',\
      {'network' : resp.json()})
  except Exception as ex:
    messages.error(request, 'Your institution\'s CertChain node \
      is not available at this time.')
    return render(request, 'certchain/overview.html', {})
예제 #4
0
파일: views.py 프로젝트: jxguan/CertChain
def manage_certifications(request):
  try:
    resp = requests.get(create_rpc_url('/all_certifications'))
    return render(request, 'certchain/certifications.html',\
      {'certifications' : resp.json()})
  except Exception as ex:
    messages.error(request, 'Your institution\'s CertChain node \
      is not available at this time: ' + str(ex))
    return render(request, 'certchain/certifications.html', {})
예제 #5
0
파일: views.py 프로젝트: jxguan/CertChain
def get_document(request, docid, type):
  try:
      resp = requests.get(create_rpc_url('/document/' + docid))
      json = resp.json()
      return render(request, 'public/'+ type + '.html',
        {'docid' : docid, 'doc' : json['contents'], 'raw_data': resp.text})
  except Exception as ex:
    messages.error(request, 'Unable to retrieve ' + type + ' at this time: ' + str(ex))
    return redirect(reverse('certchain:manage_certifications'))
예제 #6
0
파일: views.py 프로젝트: jxguan/CertChain
def end_peering(request):
  if request.method == 'POST':
    addr = request.POST['addr']
    resp = requests.post(create_rpc_url('/end_peering/' + addr))
    if resp.status_code == 200 and resp.text == 'OK':
      messages.success(request,\
        'Your peering termination request was successfully submitted.')
    else:
      messages.error(request,\
        'An error occurred while processing your \
        peering termination request: ' + resp.text)
    return redirect(reverse('certchain:overview'))
  raise Http404
예제 #7
0
파일: views.py 프로젝트: jxguan/CertChain
def approve_peer_request(request):
  if request.method == 'POST':
    addr = request.POST['requesting_addr']
    resp = requests.post(create_rpc_url('/approve_peerreq/' + addr))
    if resp.status_code == 200 and resp.text == 'OK':
      messages.success(request,\
        'Your approval was submitted successfully.')
    else:
      messages.error(request,\
        'An error occurred while processing your \
        peer request approval: ' + resp.text)
    return redirect(reverse('certchain:overview'))
  raise Http404
예제 #8
0
파일: views.py 프로젝트: jxguan/CertChain
def remove_node(request):
  if request.method == 'POST':
    inst_addr = request.POST['inst_addr']
    resp = requests.post(create_rpc_url('/remove_node/' + inst_addr))
    if resp.status_code == 200 and resp.text == 'OK':
      messages.success(request,\
        'The node was removed from the list of known nodes.')
    else:
      messages.error(request,\
        'An error occurred while removing the node you specified: '
        + str(resp.text))
    return redirect(reverse('certchain:overview'))
  raise Http404
예제 #9
0
파일: views.py 프로젝트: jxguan/CertChain
def revoke_document(request):
  if request.method == 'POST':
    docid = request.POST['docid_to_revoke']
    resp = requests.post(create_rpc_url('/revoke/' + docid))
    if resp.status_code == 200:
      messages.success(request,\
        'Your document revocation request has been submitted to the network.')
    else:
      messages.error(request,\
        'An error occurred while processing your revocation \
        request: ' + str(resp.status_code))
    return redirect(reverse('certchain:manage_certifications'))
  raise Http404
예제 #10
0
파일: views.py 프로젝트: jxguan/CertChain
def student(request, student_id):
  try:
    resp = requests.get(create_rpc_url('/certifications_by_student_id/' + student_id))
    certs_by_type = defaultdict(list)
    for c in resp.json():
      certs_by_type[c['doc_type']].append(c)
    return render(request, 'public/student.html',\
      {'certs_by_type' : certs_by_type.iteritems(),
       'student_id': student_id,
      })
  except Exception as ex:
    messages.error(request, 'Your institution\'s CertChain node \
      is not available at this time: ' + str(ex))
    return render(request, 'public/student.html', {'student_id': student_id})
예제 #11
0
파일: views.py 프로젝트: jxguan/CertChain
def add_node(request):
  if request.method == 'POST':
    payload = {
      'hostname': request.POST['hostname'],
      'port': request.POST['port'],
      'address': request.POST['address']
    }
    resp = requests.post(create_rpc_url('/add_node'),
      data=json.dumps(payload))
    if resp.status_code == 200 and resp.text == 'OK':
      messages.success(request,\
        'The node was added to the list of known nodes.')
    else:
      messages.error(request,\
        'An error occurred while adding the node you specified: '
        + str(resp.text))
    return redirect(reverse('certchain:overview'))
  raise Http404
예제 #12
0
파일: views.py 프로젝트: jxguan/CertChain
def documents(request):
  studentId = request.session.get('studentId')
  if (studentId):
    try:
      resp = requests.get(create_rpc_url('/certifications_by_student_id/' +
          studentId))
      certs_by_type = defaultdict(list)
      for c in resp.json():
        print c['doc_id']
        certs_by_type[c['doc_type']].append(c)
      print 'yoo'
      return render(request, 'student/documents.html',\
      {'certs_by_type' : certs_by_type.iteritems(),
       'studentId': studentId,
      })
    except Exception as ex:
      messages.error(request, 'Your institution\'s CertChain node \
      is not available at this time: ' + str(ex))
      return render(request, 'student/documents.html', {'studentId': studentId})
  else:
    return HttpResponse("Yooo", content_type='text/plain')
예제 #13
0
파일: views.py 프로젝트: jxguan/CertChain
def raw_block(request, block_height):
  resp = requests.get(create_rpc_url('/block/' + block_height))
  return HttpResponse(resp.text, content_type='application/json')
예제 #14
0
파일: views.py 프로젝트: jxguan/CertChain
def raw_document(request, docid):
  resp = requests.get(create_rpc_url('/document/' + docid))
  return HttpResponse(resp.text, content_type='application/json')