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 generateElectorateData(): data = request.json electionId = data["election"] authorityId = data["authorityId"] try: # prepare voteService voteSvc = VoteService(electionId) # perform action voteSvc.generateElectorateData(authorityId) #patches = voteSvc.getJSONPatches() # retrieve and persist modified state patches = voteSvc.persist() syncPatches(electionId, SyncType.ROOM, patches) # update election status # voteSvc.updateStatus(1) 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({'result': 'success'})
def sendVotingCards(): electionId = request.json["election"] try: voteSvc = VoteService(electionId) # prepare voteService voteSvc.sendVotingCards() patches = voteSvc.persist() syncPatches(electionId, SyncType.ROOM, patches) # update election status voteSvc.updateStatus(3) 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({'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 setUpElection(): data = request.json electionId = data["election"] numberOfVoters = json.loads(data["numberOfVoters"]) candidates = data["candidates"] countingCircles = json.loads(data["countingCircles"]) numberOfSelections = data["numberOfSelections"] numberOfCandidates = data["numberOfCandidates"] titles = data["titles"] try: # validate vote parameters if len(candidates) != sum(numberOfCandidates): raise RuntimeError( "The numberOfCandidates must match the number of candidates") if numberOfVoters != len(countingCircles): raise RuntimeError( "The length of countingCircles must match the number of voters" ) if len(numberOfSelections) != len(numberOfCandidates): raise RuntimeError( "The length of numberOfSelections must match the length of numberOfCandidates" ) # prepare voteService voteSvc = VoteService(electionId) # perform action voteSvc.setupElection(numberOfVoters, countingCircles, candidates, numberOfCandidates, numberOfSelections, titles) #patches = voteSvc.getJSONPatches() # retrieve and persist modified state patches = voteSvc.persist() syncPatches(electionId, SyncType.ROOM, patches) # update election status voteSvc.updateStatus(1) 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({'result': 'success'})
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'})