Пример #1
0
def viewgen(id):
    username = session.get('username')
    abc = session.get('abcdefg')
    print(type(username), type(abc))
    if type(username) == type(abc):
        return redirect(url_for('home', nologin=1))
    id = int(id)
    allinfo = getallinfo()
    if id not in allinfo[0]:
        return redirect(url_for('view'))
    tablename = 'tab' + str(id)
    print(tablename)
    allinfo = gettableinfo('tab1info')
    candidate = fetchidandvote2(tablename, 'CANDIDATE')
    vote = fetchidandvote2(tablename, 'VOTES')
    length = len(candidate)
    idset = allinfo[0]
    index = idset.index(int(id))
    title = allinfo[3][index]
    subtitle = allinfo[4][index]
    starttime = allinfo[5][index]
    endtime = allinfo[6][index]
    details = fetchdetails(tablename)
    return render_template('viewgen.html',candidate = candidate,vote=vote,\
                           length=length,title = title,subtitle = subtitle,starttime = starttime,endtime=endtime,details = details)
Пример #2
0
def manage():

    if request.method == "post":
        return redirect(url_for('view'))
    id = int(request.values.get('id'))
    tablename = 'tab' + str(id)
    #print(tablename)
    allinfo = gettableinfo('tab1info')
    candidate = fetchidandvote2(tablename, 'CANDIDATE')
    vote = fetchidandvote2(tablename, 'VOTES')
    length = len(candidate)
    idset = allinfo[0]
    index = idset.index(int(id))
    title = allinfo[3][index]
    subtitle = allinfo[4][index]
    starttime = allinfo[5][index]
    endtime = allinfo[6][index]
    details = fetchdetails(tablename)
    return render_template('changegen.html',candidate = candidate,vote=vote,\
                           length=length,title = title,subtitle = subtitle,starttime = starttime,endtime=endtime,details = details)
Пример #3
0
def posted():
    ip = request.remote_addr
    length = int(request.values.get('length'))
    captcha = stripit(request.values.get('image')).upper()
    sourcestr = session['image'].upper()
    print(captcha, sourcestr)
    tablename = stripit(str(request.values.get('id')))
    id = tablename.replace('tab', '')
    if captcha != sourcestr:
        return redirect(url_for('votegen', id=id, captcha=0))
    candidates = fetchidandvote2(tablename, 'CANDIDATE')
    if checkip(ip, tablename) != 1:
        return render_template("vote_succ.html",candidates=fetchidandvote2(tablename,'CANDIDATE'),\
                   votes=fetchidandvote2(tablename,'VOTES'),length=len(candidates),voted=1)
    saveip(ip, tablename)
    id = int(tablename.replace("tab", ''))
    #print("id is",id)
    allinfo = getallinfo()
    #print(len(allinfo))
    idset = allinfo[0]
    #print(idset)
    if id not in idset:
        return render_template("hello.html",candidates=fetchidandvote2(tablename,'CANDIDATE'),\
                   votes=fetchidandvote2(tablename,'VOTES'),length=len(candidates),voted=1)
    idindex = idset.index(id)
    title = allinfo[3][idindex]
    subtitle = allinfo[4][idindex]
    minvote = allinfo[7][idindex]
    maxvote = allinfo[8][idindex]
    namelists = namelistlist(tablename)
    d = request.form
    d = d.to_dict()
    #print('d is =====',d)
    print(tablename)
    getnames = []
    #getform = []
    for i in range(1, length + 1):
        string = 'cond_' + str(i)
        getnames.append(string)
    sum = 0
    for i in range(0, length):
        sum += int(d[str(getnames[i])])
    if sum < minvote or sum > maxvote:
        return render_template("hello.html")
    for i in range(0, length):
        if int(d[str(getnames[i])]) == 1:
            upd1(tablename, str(namelists[i]))
            print('updated:', namelists[i])
    return render_template("vote_succ.html",candidates=fetchidandvote2(tablename,'CANDIDATE'),\
                           votes=fetchidandvote2(tablename,'VOTES'),length=length)
Пример #4
0
def votegen(id):
    if request.method != "GET":
        return render_template("hello.html")
    else:
        #id = int(request.values.get('id'))
        id = int(id)
        allinfo = getallinfo()
        if id not in allinfo[0]:
            return render_template('hello.html')
        if request.values.get('captcha') is not None:
            captcha = 0
        else:
            captcha = 1
        ip = str(request.remote_addr)
        tablename = 'tab' + str(id)
        svtime1 = gettime(id, 1)
        svtime2 = gettime(id, 2)
        timeArray = time.strptime(svtime1, "%Y-%m-%d %H:%M:%S")
        svstarttimestamp = time.mktime(timeArray)
        timeArray = time.strptime(svtime2, "%Y-%m-%d %H:%M:%S")
        svendtimestamp = time.mktime(timeArray)
        #print('svtime1:',svstarttimestamp)
        #print('svtime2:',svendtimestamp)
        nowtimestamp = time.time()
        #print('localtime',nowtimestamp)
        if checkip(ip, tablename) != 1:
            candidates = fetchidandvote2(tablename, 'CANDIDATE')
            return render_template("vote_succ.html",candidates=fetchidandvote2(tablename,'CANDIDATE'),\
                   votes=fetchidandvote2(tablename,'VOTES'),length=len(candidates),voted=1)
        if svendtimestamp <= nowtimestamp:
            candidates = fetchidandvote2(tablename, 'CANDIDATE')
            return render_template("vote_succ.html",candidates=fetchidandvote2(tablename,'CANDIDATE'),\
                   votes=fetchidandvote2(tablename,'VOTES'),length=len(candidates),timeout=1)

        if nowtimestamp <= svstarttimestamp:
            candidates = fetchidandvote2(tablename, 'CANDIDATE')
            return render_template("vote_succ.html",candidates=fetchidandvote2(tablename,'CANDIDATE'),\
                   votes=fetchidandvote2(tablename,'VOTES'),length=len(candidates),notyet=1)
        #print(tablename)
        allinfo = getallinfo()
        #print(len(allinfo))
        idset = allinfo[0]
        #print(idset)
        if id not in idset:
            return render_template("hello.html")
        idindex = idset.index(id)
        title = allinfo[3][idindex]
        subtitle = allinfo[4][idindex]
        minvote = allinfo[7][idindex]
        maxvote = allinfo[8][idindex]
        candidates = fetchidandvote2(tablename, 'CANDIDATE')
        votes = fetchidandvote2(tablename, 'VOTES')
        details = fetchdetails(tablename)
        length = len(candidates)
        return render_template("generate.html",tablename=tablename,title=title,subtitle=subtitle,\
                               candidates=candidates,details=details,length = length,getnames = getnames(length),votes = votes,\
                                minvote = minvote,maxvote = maxvote,captcha=captcha)
Пример #5
0
def namelistlist(tablename):
    namelist = fetchidandvote2(tablename, 'CANDIDATE')
    return namelist
Пример #6
0
def nameli(tablename):
    namelist = str(fetchidandvote2(tablename, 'CANDIDATE'))
    return namelist
Пример #7
0
import pymysql
import os
import re
import shutil
from fixer import write_in_info
from io import BytesIO
from flask import flash
import json
import random
import time, datetime
from validation import validate_picture

db = pymysql.connect("localhost", "root", "aA_iul453_bB", "test0")
voter = Flask(__name__)
voter.secret_key = 'some_secret'
namelist = str(fetchidandvote2('tab1', 'CANDIDATE'))
if namelist == -1:
    print('namelist error')
    exit(-1)


def makekey(length):
    key = ''
    for i in range(0, length):
        temp = random.choice(
            'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
        key = key + str(temp)
    print(key)
    return str(key)