-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (55 loc) · 2.07 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask, redirect, url_for, render_template, request,jsonify,flash
import mysql.connector
app = Flask(__name__)
app.config['SECRET_KEY'] = "mi sxxxxuper clxxxave secrxxxssseta"
conn=mysql.connector.connect(
host="localhost",
user="root",
password="",
db="votaciones"
)
@app.route('/', methods=['GET', 'POST'])
def home():
return redirect('auth')
@app.route('/auth', methods=['GET', 'POST'])
def auth():
if request.method == 'POST':
# Handle POST Request here
email=request.form['email']
password=request.form['password']
cur=conn.cursor()
cur.execute("SELECT email,password FROM coordinator")
data=cur.fetchall()
for dat in data:
if email==dat[0]:
if password==dat[1]:
return redirect('form')
else:
flash('Contraseña incorrecta','error')
return redirect('auth')
else:
flash('Email incorrecto','error')
return redirect('auth')
# return jsonify({"message":"ada"})
return render_template('index.html')
@app.route('/form',methods=['GET','POST'])
def form():
cur=conn.cursor()
cur.execute("SELECT * FROM county")
context=cur.fetchall()
if request.method == 'POST':
year=request.form['year']
Pparty=request.form['Pparty']
county=request.form['county']
Vcount=request.form['Vcount']
cur=conn.cursor()
cur.execute("INSERT INTO election (year,politicalParty,voteCount, codeCounty) VALUES (%s,%s,%s,%s)", (year,Pparty,Vcount,county))
conn.commit()
flash("Registro agregado.","success")
cur.execute("SELECT * FROM county")
context=cur.fetchall()
return render_template('form.html',context=context)
return render_template('form.html',context=context)
if __name__ == '__main__':
# DEBUG is SET to TRUE. CHANGE FOR PROD
app.run(port=5000, debug=True)