-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
83 lines (63 loc) · 2.34 KB
/
run.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
from app import app, totp
import socket
from app.models import *
from flask import render_template, session,request,url_for,redirect,flash
import requests
@app.route("/",methods=['GET','POST'])
def index():
if(request.method == "POST"):
aadhaarNo = request.form['aadhaarNo']
session['currentUser'] = aadhaarNo
user = Aadhaar.query.get(aadhaarNo)
entitlement = Entitlement.query.get(user.category)
if user.category == "GEN":
session['maxAmount'] = user.generalCount.count * entitlement.maxAmount
else:
session['maxAmount'] = entitlement.maxAmount
return redirect(url_for('stock'))
session.clear()
return render_template("index.html")
@app.route("/getUsage")
def getUsage():
user = Aadhaar.query.get(session['currentUser'])
return render_template("getUsage.html",name=user.name)
@app.route("/sendOtp")
def sendOtp():
beneficiary = Aadhaar.query.get(session['currentUser'])
otp = totp.now()
session['OTP'] = otp
string = "{phone_no:"+beneficiary.mobileNo+",OTP:"+otp+"}"
stringToSend = ((string)+"\n")
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect(("192.168.43.223",6000))
count = sock.send(stringToSend.encode())
return redirect(url_for('stock'))
@app.route("/verifyOtp/<string:otp>")
def verifyOtp(otp):
if session['OTP'] == otp:
return "True"
else:
return "False"
@app.route("/stock",methods=['GET','POST'])
def stock():
if(request.method == "POST"):
total = int(request.form['riceQuantity']) + int(request.form['wheatQuantity']) + int(request.form['coarseQuantity'])
session['rice'] = int(request.form['riceQuantity'])
session['wheat'] = int(request.form['wheatQuantity'])
session['coarse'] = int(request.form['coarseQuantity'])
if(total > session['maxAmount']):
flash("You are only allowed "+str(session['maxAmount'])+" KG")
return redirect(url_for('stock'))
else:
flash("A message has been sent")
return redirect(url_for("sendOtp"))
return render_template("stock.html")
@app.route("/supplier")
def supplier():
return render_template("supplier.html")
@app.route("/profile")
def profile():
user = Aadhaar.query.get(session['currentUser'])
return render_template("profile.html",aadhaarNo=user.aadhaarNo,name=user.name,address=user.address,mobileNo=user.mobileNo,category=user.category)
if __name__ == "__main__":
app.run(host="localhost", port=8000, debug=True)