예제 #1
0
def registerVote(plainText, username, password):
	"""Register plainText as the vote of user with given username and password"""
	if GlobalVariables.objects.filter(varname='electionState')[0].value != 'election':
		return False
	userlist = Users.objects.filter(username=username)
	#print len(userlist)
	if (len(userlist) == 0):
		return False
	assert(len(userlist) == 1)
	decryptedPrivateKey = cryptography.symmetricDecrypt(userlist[0].encryptedPrivateKey,password)

	certificate = cryptography.asymmetricSign(plainText,decryptedPrivateKey)
	key = RSA.importKey(decryptedPrivateKey)
	key = key.publickey().exportKey()
	assert(len(PublicKeys.objects.filter(publicKey=key)) == 1)
	publicKey = PublicKeys.objects.filter(publicKey=key)[0]

	challenobj = ChallengeStrings.objects.all()
	lenofcha = len(challenobj)
	rannum = lenofcha/2
	'''get a random number'''
	p1 = Votes(plainText=plainText, certificate=certificate, publicKey=publicKey, challengeStr = challenobj[rannum])
	p1.save()

	return True
예제 #2
0
def registerVote(plainText, username, password):
	"""Register plainText as the vote of user with given username and password"""
	if GlobalVariables.objects.filter(varname='electionState')[0].value != 'election':
		return False
	userlist = Users.objects.filter(username=username)
	#print len(userlist)
	if (len(userlist) == 0):
		return False
	assert(len(userlist) == 1)
	decryptedPrivateKey = cryptography.symmetricDecrypt(userlist[0].encryptedPrivateKey,password)

	certificate = cryptography.asymmetricSign(plainText,decryptedPrivateKey)
	key = RSA.importKey(decryptedPrivateKey)
	key = key.publickey().exportKey()
	assert(len(PublicKeys.objects.filter(publicKey=key)) == 1)
	publicKey = PublicKeys.objects.filter(publicKey=key)[0]

	challenobj = ChallengeStrings.objects.all()
	lenofcha = len(challenobj)
	rannum = lenofcha/2
	'''get a random number'''
	p1 = Votes(plainText=plainText, certificate=certificate, publicKey=publicKey, challengeStr = challenobj[rannum])
	p1.save()

	return True
예제 #3
0
def test_add_one_vote_and_return_100():

    add = Votes()
    add['result'] = 1
    add.save()

    get = report()
    _sum = get['p1']+get['p2']
    assert _sum == 100, _sum
예제 #4
0
def test_add_three_vote_and_return_100():

    for a in [1,2,1]:
        add = Votes()
        add['result'] = a
        add.save()

    get = report()
    _sum = get['p1']+get['p2']
    assert _sum == 100, _sum
예제 #5
0
def add_vote(request, poll_id):
	poll = Poll.objects.get(id=poll_id)
	choice = Choice.objects.filter(poll=poll_id).order_by('id')
	if request.method == 'POST':
		vote = request.POST.get('choice')
		if vote:
			vote = Choice.objects.get(id=vote)
			# saves the poll id, user id, and choice to the votes table
			v = Votes(poll=poll, choiceVote = vote)
			v.save()
			# redirects the user to the results page after they submit their vote
			return HttpResponseRedirect('../.')
		return render_to_response('votes.html', {'choice': choice, 'poll': poll, 'vcount': vcount,}, context_instance=RequestContext(request))
예제 #6
0
def vote_up(request, answer_id):
    if request.user.is_authenticated():
        answer = Answer.objects.get(id = answer_id)
        votos = Votes.objects.filter(author = request.user, answer = answer)
        question_id = answer.question.id       
        if len(votos) == 0:
            voto = Votes(answer = answer, author = request.user, vote = 'Up')
            voto.save()
        else:
            pass #TODO mandar un mensaje de que ya voto.
            #request.session['message'] = 'Usted ya ha votado por esta repuesta.' 
        return HttpResponseRedirect('/soporte/pregunta/' + str(question_id))
    else:
        return HttpResponseRedirect('/cuentas/login')
예제 #7
0
def addVotes(plainText, certificate):
    p1 = Votes(plainText=plainText, certificate=certificate)
    p1.save()
예제 #8
0
def addVotes(plainText,certificate):
	p1 = Votes(plainText=plainText, certificate=certificate)
	p1.save()