Beispiel #1
0
def listClients(user=None):
  if 'usertype' in session:
    if session['usertype'] == 'BiO' or session['usertype'] == 'ADM':
      return render_template('client_search.html', goto='listDetachments', CLs=db.getAllClients(), user=escape(session['user']))
    else:
      flash('Unauthorized access')
      return redirect(url_for('logout'))
def addNodeRequest():
    content = request.json
    try:
        print("in request")
        name = decryptData(PRIVATE_KEY, content['name'])
        ipaddr = decryptData(PRIVATE_KEY, content['ipaddr'])
        publicKey = content['publicKey']
        companyName = decryptData(PRIVATE_KEY, content['companyName'])
        companyID = decryptData(PRIVATE_KEY, content['companyID'])
        #verify if the node doesn't exist?
        addNodes(name, ipaddr, publicKey)
        ll = getAllClients()
        for i in ll:
            try:
                TEMP_KEY = "keys/tempKey.pem"
                saveKeyinFile(TEMP_KEY, i.publicKey)
                data = {}
                data["name"] = encryptData(TEMP_KEY, name)
                data["companyName"] = encryptData(TEMP_KEY, companyName)
                data["companyID"] = encryptData(TEMP_KEY, companyID)
                try:
                    rr = requests.post(i.callback_URL + '/addNode', json=data)
                except Exception as e:
                    print(e)
            except Exception as e:
                print(e)
        return jsonify({"code": 0, "status": "Node added"})
    except:
        return jsonify({"code": 1, "status": "Something Went Wrong here"})
def checkClient():
    content = request.json
    uid = content["uid"]
    ll = getAllClients()
    for i in ll:
        if i.uid == uid:
            return jsonify({"code": 0, "status": "Go Ahead"})
    return jsonify({"code": 1, "status": "Something went wrong"})
def getTransaction():
    content = request.json
    try:
        proposingNode = decryptData(PRIVATE_KEY, content['proposingNode'])
        transaction = decryptData(PRIVATE_KEY, content['transaction'])
        blockindex = decryptData(PRIVATE_KEY, content['blockindex'])
        timeStamp = decryptData(PRIVATE_KEY, content['timeStamp'])
        uid = decryptData(PRIVATE_KEY, content['uid'])
        addPendingTransaction(uid, proposingNode, transaction, blockindex,
                              timeStamp)
        #call client for transaction strucutre check
        ll = getAllClients()
        for i in ll:
            try:
                TEMP_KEY = "keys/tempKey.pem"
                saveKeyinFile(TEMP_KEY, i.publicKey)
                data = {}
                data["transaction"] = encryptData(TEMP_KEY, transaction)
                data["proposingNode"] = encryptData(TEMP_KEY, proposingNode)
                data["blockindex"] = encryptData(TEMP_KEY, blockindex)
                data["uid"] = encryptData(TEMP_KEY, uid)
                rr = requests.post(i.callback_URL + '/addTransaction',
                                   json=data)
            except Exception as e:
                print(e)
        ##
        #save in pending db

        #call client for verify
        return jsonify({
            "code": 0,
            "status": "Transaction is submitted to client"
        })
    except Exception as e:
        print(e)
        return jsonify({"code": 1, "status": "Something Went Wrong"})
def client(user=None):
  return render_template('client.html', client=db.getAllClients(), user=escape(session['user']))
Beispiel #6
0
def client(user=None):
    return render_template('client.html',
                           client=db.getAllClients(),
                           user=escape(session['user']))