Exemple #1
0
 def test_send_ok(self):
     shutil.rmtree(backend.election_dir(999))
     result = backend.create_election(999, 3, 3)
     self.assertTrue(result)
     self.assertTrue(backend.guarantor_send_hash(999, 1, "ciao"))
     self.assertTrue(backend.guarantor_send_hash(999, 3, "ciao"))
     self.assertTrue(backend.guarantor_send_hash(999, 2, "ciao"))
Exemple #2
0
 def test_status(self):
     shutil.rmtree(backend.election_dir(999))
     result = backend.create_election(999, 3, 3)
     self.assertTrue(result)
     self.assertTrue(backend.guarantor_send_hash(999, 1, "ciao"))
     self.assertTrue(backend.guarantor_send_hash(999, 2, "ciao"))
     self.assertTrue(backend.guarantor_send_hash(999, 3, "ciao"))
     self.assertTrue(backend.candidate_send_passphrase(999, 3, "ciao"))
     self.assertTrue(backend.candidate_send_passphrase(999, 2, "ciao"))
     self.assertTrue(backend.candidate_send_passphrase(999, 1, "ciao"))
     self.assertTrue(backend.guarantor_confirm_passphrase(999, 2, "ciao"))
     self.assertTrue(backend.guarantor_confirm_passphrase(999, 1, "ciao"))
     self.assertTrue(backend.guarantor_confirm_passphrase(999, 3, "ciao"))
     ar = backend.election_state(999)
     i = 0
     for s in ar:
         i = i + 1
         print("riga {}: {}".format(i, s))
Exemple #3
0
def send_passphrase():
    message = None
    votation_id = int(request.form['votation_id'])
    passphrase = request.form['passphrase']
    v = votation.load_votation_by_id(votation_id)
    u = current_user.u
    if v.votation_status == votation.STATUS_WAIT_FOR_GUAR_HASHES:
        g = guarantor.load_guarantor(v.votation_id, u.user_id)
        # TODO scramble the key in the javascript
        # TODO handle this with ajax
        # TODO error handling
        backend.guarantor_send_hash(votation_id, g.order_n, passphrase)
        message = "Custode, la tua chiave è stata registrata."
        guarantor.set_hash_ok(u.user_id, votation_id)
        # check if every guarantors has sent the hash
        if guarantor.guarantors_hash_complete(votation_id):
            votation.update_status(votation_id,
                                   votation.STATUS_WAIT_FOR_CAND_KEYS)
    if v.votation_status == votation.STATUS_WAIT_FOR_CAND_KEYS:
        c = candidate.load_candidate(v.votation_id, u.user_id)
        backend.candidate_send_passphrase(votation_id, c.order_n, passphrase)
        message = "Candidato, la tua chiave è stata registrata."
        candidate.set_passphrase_ok(u.user_id, votation_id)
        if candidate.candidates_passphrases_complete(votation_id):
            votation.update_status(votation_id,
                                   votation.STATUS_WAIT_FOR_GUAR_KEYS)
    if v.votation_status == votation.STATUS_WAIT_FOR_GUAR_KEYS:
        g = guarantor.load_guarantor(v.votation_id, u.user_id)
        if backend.guarantor_confirm_passphrase(votation_id, g.order_n,
                                                passphrase):
            message = "Custode, la tua chiave è stata confermata."
        else:
            message = "Custode, la chiave che hai inserito non è corretta."
        guarantor.set_passphrase_ok(u.user_id, votation_id)
        if guarantor.guarantors_passphrase_complete(votation_id):
            votation.update_status(votation_id, votation.STATUS_CALCULATION)
            # suspence...
            votation.update_status(votation_id, votation.STATUS_ENDED)
    return render_template('thank_you_template.html',
                           pagetitle="Thank you",
                           message=message)