-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
49 lines (45 loc) · 1.46 KB
/
app.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
import requests
import flask
import json
import subprocess
import os
from flask_cors import CORS
import threading
import smtplib
app = flask.Flask(__name__)
voteData=''
CORS(app)
#1
@app.route('/api/v1/create',methods= ['POST'])
def createContract():
''' creates vote contract '''
global voteData
cid=flask.request.json['candidateid']
voteData=cid
cid=cid.split()
cid=''.join(cid)
os.system(r".\\azure-vote\\node_modules\\.bin\\wdio .\\azure-vote\\wdio.conf.js --suite contract "+cid)
return flask.Response(status=200)
@app.route('/api/v1/verify',methods=['GET'])
def takeaction():
''' does verification '''
#profile values send as cli arguments
trace=os.popen("python hashing.py").read()
ver=os.system(r".\\azure-vote\\node_modules\\.bin\\wdio .\\azure-vote\\wdio.conf.js --suite verify "+trace)
if ver!=0:
return flask.Response(status=401)
else:
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login("dummycred", "dummycred")
message = "Voted for "+voteData
s.sendmail("dummysendcred", "dummyrecvcred", message)
s.quit()
return flask.Response(status=200)
@app.route('/api/v1/action',methods=['GET'])
def verify():
''' verfies whether the vote is valid '''
os.system(r".\\azure-vote\\node_modules\\.bin\\wdio .\\azure-vote\\wdio.conf.js --suite action")
return flask.Response(status=200)
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5000)