def castVote(): data = request.json print(data) electionId = data["election"] selection = data["selection"] selection = [int(x) for x in selection] selection.sort() voterId = data["voterId"] votingCode = data["votingCode"] manipulatedPublicCredential = data["manipulatedPublicCredential"] manipulatedPublicKey = data["manipulatedPublicKey"] if len(selection) == 0: return make_error(400, "Empty selection") try: # prepare voteService voteSvc = VoteService(electionId) # perform action voteSvc.castVote(voterId, selection, votingCode, manipulatedPublicCredential, manipulatedPublicKey) # retrieve and persist modified state patches = voteSvc.persist() syncPatches(electionId, SyncType.ROOM, patches) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] return make_error( 500, '%s:%s: %s. %s' % (fname, exc_tb.tb_lineno, e, traceback.format_exc())) return json.dumps({'result': 'success'})
def startDecryptionPhase(): data = request.json electionId = data["election"] try: # prepare voteService voteSvc = VoteService(electionId) voteSvc.startDecryption() # retrieve and persist modified state patches = voteSvc.persist() syncPatches(electionId, SyncType.ROOM, patches) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e)) return json.dumps({'id': str(id)})
def revealCode(): data = request.json electionId = data["election"] voterId = int(data["voterId"]) codeIndex = int(data["codeIndex"]) try: # prepare voteService voteSvc = VoteService(electionId) # perform action voteSvc.revealCode(voterId, codeIndex) # retrieve and persist modified state patches = voteSvc.persist() syncPatches(electionId, SyncType.ROOM, patches) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e)) return json.dumps({'id': str(id)})
def setAutoMode(): data = request.json electionId = data["election"] authorityId = data["authorityId"] value = data["value"] try: # prepare voteService voteSvc = VoteService(electionId) # perform action voteSvc.authorities[authorityId].autoCheck = value # retrieve and persist modified state patches = voteSvc.persist() syncPatches(electionId, SyncType.ROOM, patches) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e)) return json.dumps({'id': str(id)})
def abortVote(): data = request.json electionId = data["election"] voterId = data["voterId"] try: # prepare voteService voteSvc = VoteService(electionId) # perform action voteSvc.abortVote(voterId) # retrieve and persist modified state patches = voteSvc.persist() syncPatches(electionId, SyncType.ROOM, patches) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] return make_error( 500, '%s:%s: %s. %s' % (fname, exc_tb.tb_lineno, e, traceback.format_exc())) return json.dumps({'result': 'success'})