def give_key(request): """ Another node is telling us that they are granting us the ability to make privledged transactions with them. They are giving us a key we must store. (The key must be verified.) """ # TODO: THIS IS TERRIBLE! p = request.POST uri = hashless(p['uri']) key_theirs = p['key'] if 'key' in p else None # Lookup or create node. # TODO: For now assume it exists. Must deal with spam/fraud later. node = None try: node = Node.objects.get(uri=uri) except Node.DoesNotExist: node = Node(uri=uri) node.datetime_added = datetime.today() node.is_yet_to_resolve = True #node.save() # Maybe they want to change their key if node.key_theirs and node.key_theirs_confirmed: node.new_key_theirs = key_theirs node.save() # TODO: Schedule a job to confirm the key return node.key_theirs = key_theirs node.key_theirs_confirmed = False node.new_key_theirs = '' node.save()