-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic.py
233 lines (195 loc) · 6.78 KB
/
public.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
from flask import *
from database import *
import uuid
from datetime import *
from email.mime.text import MIMEText
from flask_mail import Mail
public=Blueprint('public',__name__)
@public.route('/')
def home():
session.clear()
return render_template('home.html')
@public.route('/login',methods=['get','post'])
def login():
session.clear()
if 'submit' in request.form:
uname=request.form['uname']
passw=request.form['password']
q="SELECT * FROM `login` WHERE `username`='%s' AND `password`='%s'"%(uname,passw)
res=select(q)
if res:
session['lid']=res[0]['login_id']
if res[0]['login_type']=='admin':
flash('WELCOME ADMIN')
return redirect(url_for('admin.admin_home'))
elif res[0]['login_type']=='pending':
flash("YOUR REQUEST IS PENDING")
elif res[0]['login_type']=='reject':
flash('YOU WHERE REJECTED!!, CONTACT US')
elif res[0]['login_type']=='district':
q="SELECT * FROM `district` WHERE `login_id`='%s'"%(res[0]['login_id'])
res1=select(q)
session['district_id']=res1[0]['district_id']
flash('WELCOME DISTRICT MANAGER')
return redirect(url_for('district.district_home'))
elif res[0]['login_type']=='booth':
q="SELECT * FROM `booth` WHERE `login_id`='%s'"%(res[0]['login_id'])
res1=select(q)
session['booth_id']=res1[0]['booth_id']
return redirect(url_for("booth.booth_home"))
flash('WELCOME BOOTH MANAGER')
elif res[0]['login_type']=='candidate':
q="SELECT * FROM `candidate` WHERE `login_id`='%s'"%(res[0]['login_id'])
res1=select(q)
session['cid']=res1[0]['candidate_id']
flash('WELCOME CANDIDATE')
return redirect(url_for('candidate.candidate_home'))
elif res[0]['login_type']=='voter':
q="SELECT * FROM `voter` WHERE `login_id`='%s'"%(res[0]['login_id'])
res1=select(q)
session['voter_id']=res1[0]['voter_id']
flash('WELCOME VOTER')
return redirect(url_for('voter.voter_home'))
else:
flash('WRONG USERNAME OR PASSWORD')
return render_template('login.html')
@public.route('/candidate_registration',methods=['get','post'])
def candidate_registration():
data={}
q="SELECT * FROM `district`"
res=select(q)
data['district']=res
q="SELECT * FROM `election`"
res=select(q)
data['election']=res
if 'submit' in request.form:
election=request.form['election']
district=request.form['district']
fname=request.form['fname']
lname=request.form['lname']
img=request.files['image']
path="static/"+str(uuid.uuid4())+img.filename
img.save(path)
age=request.form['age']
dob=request.form['dob']
place=request.form['place']
city=request.form['city']
state=request.form['state']
phone=request.form['phone']
aadhar=request.form['aadhar']
email=request.form['email']
uname=request.form['uname']
password=request.form['password']
d=datetime.strptime(dob, '%Y-%m-%d')
a=datetime.today()
v=a.year-d.year
if v<25:
flash('UNDER AGE')
else:
q1="SELECT * FROM `candidate` WHERE `aadhar`='%s'"%(aadhar)
res1=select(q1)
q2="SELECT * FROM `candidate` WHERE `phone`='%s'"%(phone)
res2=select(q2)
q3="SELECT * FROM `candidate` WHERE `email`='%s'"%(email)
res3=select(q3)
q4="SELECT * FROM `login` WHERE `username`='%s'"%(uname)
res4=select(q4)
if res2:
flash('PHONE NUMBER IS ALREADY TAKEN')
elif res3:
flash('EMAIL IS ALREADY TAKEN')
elif res4:
flash('USERNAME IS ALREADY TAKEN')
elif res1:
flash('REGISTRATION FAILD BECAUSE AADHAR NUMBER ALREADY EXIST')
else:
q="INSERT INTO `login`(`username`,`password`,`login_type`) VALUES ('%s','%s','pending')"%(uname,password)
id=insert(q)
q1="INSERT INTO `candidate`(`login_id`,`election_id`,`district_id`,`first_name`,`last_name`,`image`,`age`,`dob`,`place`,`city`,`state`,`phone`,`email`,`aadhar`) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"%(id,election,district,fname,lname,path,age,dob,place,city,state,phone,email,aadhar)
insert(q1)
flash('DETAILS SUBMITED')
return render_template('candidate_registration.html',data=data)
@public.route('/voter_registration',methods=['get','post'])
def voter_registration():
data={}
q="SELECT * FROM `district`"
res=select(q)
data['disup']=res
if 'submitz' in request.form:
disid=request.form['disup']
q="SELECT * FROM `booth` WHERE district_id='%s'"%disid
res=select(q)
data['booth']=res
q=""
res=q
data['disup']=res
q="SELECT * FROM `election`"
res=select(q)
data['election']=res
if 'submit' in request.form:
booth=request.form['booth']
election=request.form['election']
fname=request.form['fname']
lname=request.form['lname']
dob=request.form['dob']
age=request.form['age']
place=request.form['place']
city=request.form['city']
state=request.form['state']
phone=request.form['num']
email=request.form['email']
uname=request.form['uname']
passs=request.form['psw']
aadhar=request.form['aadhar']
d= datetime.strptime(dob, '%Y-%m-%d')
a=datetime.today()
v=a.year-d.year
print(v,"...")
print(d)
if v<18:
flash('UNDER AGE')
else:
q1="SELECT * FROM `voter` WHERE `aadhar`='%s'"%(aadhar)
res1=select(q1)
q2="SELECT * FROM `voter` WHERE `phone`='%s'"%(phone)
res2=select(q2)
q3="SELECT * FROM `voter` WHERE `email`='%s'"%(email)
res3=select(q3)
q4="SELECT * FROM `login` WHERE `username`='%s'"%(uname)
res4=select(q4)
if res2:
flash('PHONE NUMBER IS ALREADY TAKEN')
elif res3:
flash('EMAIL IS ALREADY TAKEN')
elif res4:
flash('USERNAME IS ALREADY TAKEN')
elif res1:
flash('REGISTRATION FAILD BECAUSE AADHAR NUMBER ALREADY EXIST')
else:
q="INSERT INTO `login`(`username`,`password`,`login_type`) VALUES ('%s','%s','pending')"%(uname,passs)
login_id=insert(q)
q="INSERT INTO `voter`(`login_id`,`booth_id`,`election_id`,`first_name`,`last_name`,`age`,`dob`,`place`,`city`,`state`,`phone`,`email`,`aadhar`)VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"%(login_id,booth,election,fname,lname,age,dob,place,city,state,phone,email,aadhar)
insert(q)
flash('REGISTERED')
try:
gmail = smtplib.SMTP('smtp.gmail.com', 587)
gmail.ehlo()
gmail.starttls()
gmail.login('projectsriss2020@gmail.com','messageforall')
except Exception as e:
print("Couldn't setup email!!"+str(e))
msg = MIMEText("Your Username is " + uname +" and password is " + passs )
# msg = MIMEText("Your password is Haii")
msg['Subject'] = 'Your Username and Password'
msg['To'] = email
msg['From'] = 'projectsriss2020@gmail.com'
try:
gmail.send_message(msg)
print(msg)
print(email)
except Exception as e:
print("COULDN'T SEND EMAIL", str(e))
# For Message Close
# return jsonify({'tasks':"success"})
return redirect(url_for('public.voter_registration'))
return render_template("voter_registration.html",data=data)