def postIdentity(self, data, decrypted): connection = Connection('localhost',27021) db = connection.yadaserver collection = db.identities node = Node(public_key = data['public_key']) node.sync(decrypted) node.save() return {}
def createIdentity(self, data, decrypted): node = Node({}, decrypted) node.save() return { 'public_key': node.get('public_key'), 'method': 'GET', 'data': encrypt(node.get('private_key'), node.get('private_key'), json.dumps(node.get())) }
def postFriend(self, data, decrypted): node = Node(public_key = data['public_key']) if 'messages' not in decrypted['data']: decrypted['data']['messages'] = [] if 'friends' not in decrypted['data']: decrypted['data']['friends'] = [] if 'public_key' not in decrypted: decrypted['public_key'] = [] if 'private_key' not in decrypted: decrypted['private_key'] = [] friend = Node(decrypted) node.addFriend(friend.get()) node.save() return {}
def onMessage(self, inbound, isBinary): """ As soon as any data is received, write it back. """ print 'got data!' f = open('/home/phablet/yadaserver.log', 'a') try: inboundObj = json.loads(inbound) if "METHOD" in inboundObj and inboundObj[ 'METHOD'] == "CREATE_IDENTITY": f.write('got identity message') f.close() n = Node({}, {"name": ""}) n._data['idlabel'] = inboundObj['DATA'] n.save() return if "METHOD" in inboundObj and inboundObj[ 'METHOD'] == "UPDATE_IDENTITY": f.write('got update identity message') f.close() print json.dumps(inboundObj, indent=2) n = Node(inboundObj['DATA']) n.save() return except: pass try: f.write('|---|%s|---|\n' % inbound) #f.write(json.dumps(inbound)) #response = nodeComm.handlePacket(inbound) #returnData = json.dumps(response) """ This is generally where a qr scanner would forward the object to postFriend api endpoint. instead, we're going to """ print "about to start notify.py" r = requests.get(inbound) friend = r.text call(['python', '/home/phablet/notify.py', friend]) self.sendMessage('OK') except: exc_type, exc_value, exc_traceback = sys.exc_info() lines = traceback.format_exception(exc_type, exc_value, exc_traceback) f.write(''.join('!! ' + line for line in lines)) self.transport.write('Input not valid.') f.close()
def onMessage(self, inbound, isBinary): """ As soon as any data is received, write it back. """ print 'got data!' f = open('/home/phablet/yadaserver.log', 'a') try: inboundObj = json.loads(inbound) if "METHOD" in inboundObj and inboundObj['METHOD'] == "CREATE_IDENTITY": f.write('got identity message') f.close() n = Node({}, {"name": ""}) n._data['idlabel'] = inboundObj['DATA'] n.save() return if "METHOD" in inboundObj and inboundObj['METHOD'] == "UPDATE_IDENTITY": f.write('got update identity message') f.close() print json.dumps(inboundObj, indent=2) n = Node(inboundObj['DATA']) n.save() return except: pass try: f.write('|---|%s|---|\n' % inbound) #f.write(json.dumps(inbound)) #response = nodeComm.handlePacket(inbound) #returnData = json.dumps(response) """ This is generally where a qr scanner would forward the object to postFriend api endpoint. instead, we're going to """ print "about to start notify.py" r = requests.get(inbound) friend = r.text call (['python', '/home/phablet/notify.py', friend]) self.sendMessage('OK') except: exc_type, exc_value, exc_traceback = sys.exc_info() lines = traceback.format_exception(exc_type, exc_value, exc_traceback) f.write(''.join('!! ' + line for line in lines)) self.transport.write('Input not valid.') f.close()
def createIdentity(self, data, decrypted): node = Node({}, decrypted) node.save() return {'public_key': node.get('public_key'), 'method': 'GET', 'data': encrypt(node.get('private_key'), node.get('private_key'), json.dumps(node.get()))}