コード例 #1
0
ファイル: default.py プロジェクト: himanshu612/evote
def vote():
    import hashlib

    response.menu = []
    election_id = request.args(0, cast=int)
    voter_uuid = request.args(1)
    election = db.election(election_id) or redirect(URL("invalid_link"))
    voter = db(db.voter.election_id == election_id)(db.voter.voter_uuid == voter_uuid).select().first() or redirect(
        URL("invalid_link")
    )
    if not DEBUG_MODE and voter.voted:
        redirect(URL("voted_already"))

    if election.deadline and request.now > election.deadline:
        session.flash = T("Election is closed")
        if voter.voted:
            session.flash += T("Your vote was recorded")
        else:
            session.flash += T("Your vote was NOT recorded")
        redirect(URL("results", args=election.id))
    response.subtitle = election.title + " / Vote"
    form = ballot2form(election.ballot_model, readonly=False)
    if form.accepted:
        results = {}
        for_update = not db._uri.startswith("sqlite")  # not suported by sqlite
        # if not for_update: db.executesql('begin immediate transaction;')
        ballot = db(db.ballot.election_id == election_id)(db.ballot.voted == False).select(
            orderby="<random>", limitby=(0, 1), for_update=for_update
        ).first() or redirect(URL("no_more_ballots"))
        ballot_content = form2ballot(
            election.ballot_model, token=ballot.ballot_uuid, vars=request.post_vars, results=results
        )
        signature = "signature-" + sign(ballot_content, election.private_key)
        ballot.update_record(
            results=str(results),
            ballot_content=ballot_content,
            signature=signature,
            voted=True,
            assigned=True,
            voted_on=request.now,
        )
        voter.update_record(voted=True)
        link = URL("ballot", args=(ballot.ballot_uuid, ballot.signature), scheme="http")

        message = message_replace(
            election.voted_email,
            link=link,
            election_id=election.id,
            owner_email=election.created_by.email,
            title=election.title,
            signature=signature,
        )
        emailed = email_voter_and_managers(election, voter, ballot, message)
        session.flash = (
            T("Your vote was recorded and we sent you an email")
            if emailed
            else T("Your vote was recorded but we failed to email you")
        )
        redirect(link)
    return dict(form=form)
コード例 #2
0
ファイル: default.py プロジェクト: tazjel/evote
def start_callback():
    election = db.election(request.args(0, cast=int)) or redirect(URL('index'))
    check_closed(election)
    form = SQLFORM.factory(
        submit_button=T('Email Voters and Start Election Now!'))
    form.element(_type='submit').add_class('btn')
    failures = []
    emails = []
    owner_email = election.created_by.email
    if form.process().accepted:
        ballot_counter = db(db.ballot.election_id == election.id).count()
        for email in regex_email.findall(election.voters):
            email = email.lower()
            voter = db(db.voter.election_id==election.id)\
                (db.voter.email==email).select().first()
            if voter:
                voter_uuid = voter.voter_uuid
            else:
                # create a voter
                voter_uuid = 'voter-' + uuid()
                voter = db.voter.insert(election_id=election.id,
                                        voter_uuid=voter_uuid,
                                        email=email,
                                        invited_on=None)
                # create a ballot
                ballot_counter += 1
                ballot_uuid = 'ballot-%i-%.6i' % (election.id, ballot_counter)
                blank_ballot_content = blank_ballot(ballot_uuid)
                signature = 'signature-' + sign(blank_ballot_content,
                                                election.private_key)
                db.ballot.insert(election_id=election.id,
                                 ballot_content=blank_ballot_content,
                                 ballot_uuid=ballot_uuid,
                                 signature=signature)
            link_vote = URL('vote',
                            args=(election.id, voter_uuid),
                            scheme=SCHEME)
            link_ballots = URL('ballots', args=election.id, scheme=SCHEME)
            link_results = URL('results', args=election.id, scheme=SCHEME)
            body = message_replace(election.vote_email,
                                   election_id=election.id,
                                   owner_email=owner_email,
                                   title=election.title,
                                   link=link_vote,
                                   link_ballots=link_ballots,
                                   link_results=link_results)
            subject = '%s [%s]' % (election.title, election.id)
            emails.append((voter, email, subject, body))
        db.commit()
        sender = election.email_sender or mail.settings.sender
        for voter, to, subject, body in emails:
            if mail.send(to=to, subject=subject, message=body, sender=sender):
                db(db.voter.id == voter).update(invited_on=request.now)
            else:
                failures.append(to)
        if not failures:
            session.flash = T('Emails sent successfully')
            redirect(URL('elections'), client_side=True)
    return dict(form=form, failures=failures, election=election)
コード例 #3
0
ファイル: default.py プロジェクト: tazjel/evote
def vote():
    import hashlib
    response.menu = []
    election_id = request.args(0, cast=int)
    voter_uuid = request.args(1)
    election = db.election(election_id) or redirect(URL('invalid_link'))
    voter = db(db.voter.election_id==election_id)\
        (db.voter.voter_uuid==voter_uuid).select().first() or \
        redirect(URL('invalid_link'))
    if not DEBUG_MODE and voter.voted:
        redirect(URL('voted_already'))

    if election.deadline and request.now > election.deadline:
        session.flash = T('Election is closed')
        if voter.voted:
            session.flash += T('Your vote was recorded')
        else:
            session.flash += T('Your vote was NOT recorded')
        redirect(URL('results', args=election.id))
    response.subtitle = election.title + ' / Vote'
    form = ballot2form(election.ballot_model, readonly=False)
    form.process()
    if form.accepted:
        results = form.vars
        for_update = not db._uri.startswith('sqlite')  # not suported by sqlite
        #if not for_update: db.executesql('begin immediate transaction;')
        ballot = db(db.ballot.election_id==election_id)\
            (db.ballot.voted==False).select(
            orderby='<random>',limitby=(0,1),for_update=for_update).first() \
            or redirect(URL('no_more_ballots'))
        ballot_content = form2ballot(election.ballot_model,
                                     token=ballot.ballot_uuid,
                                     vars=request.post_vars,
                                     results=results)
        signature = 'signature-' + sign(ballot_content, election.private_key)
        ballot.update_record(results=results,
                             ballot_content=ballot_content,
                             signature=signature,
                             voted=True,
                             assigned=True,
                             voted_on=request.now)
        voter.update_record(voted=True)
        link = URL('ballot',
                   args=(ballot.ballot_uuid, ballot.signature),
                   scheme='http')

        body = message_replace(election.voted_email,
                               link=link,
                               election_id=election.id,
                               owner_email=election.created_by.email,
                               title=election.title,
                               signature=signature)
        emailed = email_voter_and_managers(election, voter, ballot, body)
        session.flash = \
            T('Your vote was recorded and we sent you an email') \
            if emailed else \
            T('Your vote was recorded but we failed to email you')
        redirect(URL('recorded', vars=dict(link=link)))
    return dict(form=form)
コード例 #4
0
ファイル: default.py プロジェクト: vnbang2003/evote
def start_callback():
    election = db.election(request.args(0,cast=int)) or redirect(URL('index'))
    check_closed(election)
    form = SQLFORM.factory(
        submit_button=T('Email Voters and Start Election Now!'))
    form.element(_type='submit').add_class('btn')
    failures = []
    emails = []
    owner_email = election.created_by.email
    if form.process().accepted:
        ballot_counter = db(db.ballot.election_id==election.id).count()
        for email in regex_email.findall(election.voters):
            voter = db(db.voter.election_id==election.id)\
                (db.voter.email==email).select().first()
            if voter:
                voter_uuid = voter.voter_uuid
            else:
                # create a voter
                voter_uuid = 'voter-'+uuid()
                voter = db.voter.insert(
                    election_id=election.id,
                    voter_uuid=voter_uuid,
                    email=email,invited_on=None)
                # create a ballot
                ballot_counter+=1
                ballot_uuid = 'ballot-%i-%.6i' % (election.id,ballot_counter)
                blank_ballot_content = blank_ballot(ballot_uuid)
                signature = 'signature-'+sign(blank_ballot_content,
                                              election.private_key)
                db.ballot.insert(
                    election_id=election.id,
                    ballot_content = blank_ballot_content,
                    ballot_uuid=ballot_uuid,
                    signature = signature)
            link_vote = URL('vote',args=(election.id,voter_uuid),scheme=SCHEME)
            link_ballots = URL('ballots',args=election.id,scheme=SCHEME)
            link_results = URL('results',args=election.id,scheme=SCHEME)
            message = message_replace(election.vote_email,
                                      election_id = election.id,
                                      owner_email = owner_email,
                                      title=election.title,
                                      link=link_vote,
                                      link_ballots=link_ballots,
                                      link_results=link_results)
            subject = '%s [%s]' % (election.title, election.id)
            print message
            emails.append((voter,email,subject,message))
        db.commit()
        sender = election.email_sender or mail.settings.sender
        for voter, to, subject, message in emails:
            if meta_send2(to=to,subject=subject,message=message,
                          sender=sender, reply_to=sender):
                db(db.voter.id==voter).update(invited_on=request.now)
            else:
                failures.append(to)
        if not failures:
            session.flash = T('Emails sent successfully')
            redirect(URL('elections'),client_side=True)
    return dict(form=form,failures=failures,election=election)
コード例 #5
0
ファイル: default.py プロジェクト: mdipierro/evote
def vote():    
    import hashlib
    response.menu = []
    election_id = request.args(0,cast=int)
    voter_uuid = request.args(1)
    election = db.election(election_id) or redirect(URL('invalid_link'))       
    voter = db(db.voter.election_id==election_id)\
        (db.voter.voter_uuid==voter_uuid).select().first() or \
        redirect(URL('invalid_link'))
    if not DEBUG_MODE and voter.voted:
        redirect(URL('voted_already'))
    
    if election.deadline and request.now>election.deadline:
        session.flash = T('Election is closed')
        if voter.voted:
            session.flash += T('Your vote was recorded')
        else:
            session.flash += T('Your vote was NOT recorded')
        redirect(URL('results',args=election.id))
    response.subtitle = election.title + ' / Vote'
    form = ballot2form(election.ballot_model, readonly=False)
    form.process()
    if form.accepted:
        results = form.vars
        for_update = not db._uri.startswith('sqlite') # not suported by sqlite
        #if not for_update: db.executesql('begin immediate transaction;')
        ballot = db(db.ballot.election_id==election_id)\
            (db.ballot.voted==False).select(
            orderby='<random>',limitby=(0,1),for_update=for_update).first() \
            or redirect(URL('no_more_ballots'))
        ballot_content = form2ballot(election.ballot_model,
                                     token=ballot.ballot_uuid,
                                     vars=request.post_vars,results=results)
        signature = 'signature-'+sign(ballot_content,election.private_key)
        ballot.update_record(results=results,
                             ballot_content=ballot_content,
                             signature=signature,
                             voted=True,assigned=True,voted_on=request.now)
        voter.update_record(voted=True)
        link = URL('ballot',args=(ballot.ballot_uuid,ballot.signature), scheme='http')

        body = message_replace(election.voted_email,link=link,
                                  election_id=election.id,
                                  owner_email = election.created_by.email,
                                  title=election.title,signature=signature)
        emailed = email_voter_and_managers(election,voter,ballot,body)
        session.flash = \
            T('Your vote was recorded and we sent you an email') \
            if emailed else \
            T('Your vote was recorded but we failed to email you')
        redirect(URL('recorded',vars=dict(link=link)))
    return dict(form=form)
コード例 #6
0
ファイル: default.py プロジェクト: himanshu612/evote
def start_callback():
    election = db.election(request.args(0, cast=int)) or redirect(URL("index"))
    form = SQLFORM.factory(submit_button=T("Email Voters and Start Election Now!"))
    form.element(_type="submit").add_class("btn")
    failures = []
    emails = []
    owner_email = election.created_by.email
    if form.process().accepted:
        ballot_counter = db(db.ballot.election_id == election.id).count()
        for email in regex_email.findall(election.voters):
            voter = db(db.voter.election_id == election.id)(db.voter.email == email).select().first()
            if voter:
                voter_uuid = voter.voter_uuid
            else:
                # create a voter
                voter_uuid = "voter-" + uuid()
                db.voter.insert(election_id=election.id, voter_uuid=voter_uuid, email=email, invited_on=request.now)
                # create a ballot
                ballot_counter += 1
                ballot_uuid = "ballot-%i-%.6i" % (election.id, ballot_counter)
                blank_ballot_content = blank_ballot(ballot_uuid)
                signature = "signature-" + sign(blank_ballot_content, election.private_key)
                db.ballot.insert(
                    election_id=election.id,
                    ballot_content=blank_ballot_content,
                    ballot_uuid=ballot_uuid,
                    signature=signature,
                )
            link_vote = URL("vote", args=(election.id, voter_uuid), scheme=SCHEME)
            link_ballots = URL("ballots", args=election.id, scheme=SCHEME)
            link_results = URL("results", args=election.id, scheme=SCHEME)
            message = message_replace(
                election.vote_email,
                election_id=election.id,
                owner_email=owner_email,
                title=election.title,
                link=link_vote,
                link_ballots=link_ballots,
                link_results=link_results,
            )
            subject = "%s [%s]" % (election.title, election.id)
            emails.append((email, subject, message))
        db.commit()
        sender = election.email_sender or mail.settings.sender
        for to, subject, message in emails:
            if not meta_send(to=to, subject=subject, message=message, sender=sender, reply_to=sender):
                failures.append(email)
        if not failures:
            session.flash = T("Emails sent successfully")
            redirect(URL("elections"), client_side=True)
    return dict(form=form, failures=failures, election=election)
コード例 #7
0
ファイル: default.py プロジェクト: marbdq/evote
def start_callback():
    import hashlib
    election = db.election(request.args(0,cast=int)) or redirect(URL('index'))
    form = FORM(INPUT(_type='submit',
                      _value=T('Email Voters and Start Election Now!')))
    failures = []
    if form.process().accepted:
        ballot_counter = db(db.ballot.election_id==election.id).count()
        for email in regex_email.findall(election.voters):
            voter = db(db.voter.election_id==election.id)\
                (db.voter.email==email).select().first()
            if voter:
                voter_uuid = voter.voter_uuid
            else:
                # create a voter
                voter_uuid = 'voter-'+uuid()
                db.voter.insert(
                    election_id=election.id,
                    voter_uuid=voter_uuid,
                    email=email,invited_on=request.now)
                # create a ballot
                ballot_counter+=1
                ballot_uuid = 'ballot-%i-%.6i' % (election.id,ballot_counter)
                blank_ballot_content = blank_ballot(ballot_uuid)
                signature = 'signature-'+sign(blank_ballot_content,
                                              election.private_key)
                db.ballot.insert(
                    election_id=election.id,
                    ballot_content = blank_ballot_content,
                    ballot_uuid=ballot_uuid,
                    signature = signature)
            link = URL('vote',args=(election.id,voter_uuid),scheme='https')
            message = message_replace(election.vote_email,
                              title=election.title,link=link)
            if not mail.send(to=email,subject=election.title,message=message):
                failures.append(email)
        if not failures:
            session.flash = T('Emails sent successfully')
            redirect(URL('elections'),client_side=True)
    return dict(form=form,failures=failures,election=election)