-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp10.py
100 lines (84 loc) · 3.14 KB
/
app10.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
#!/usr/bin/python
from flask import Flask, request, redirect, render_template, url_for
from flask_mysqldb import MySQL
from functools import wraps
app = Flask(__name__)
## Configure DB
app.config['MYSQL_HOST'] = '127.0.0.1'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = 'root123'
app.config['MYSQL_DB'] = 'flaskapp'
mysql = MySQL(app)
@app.route('/')
def index():
return render_template('methods.html')
def auth_update(f):
@wraps(f)
def auth_dec(*args, **kwargs):
return redirect('/Authenticate')
return auth_dec
def auth_users(f):
@wraps(f)
def auth_users(*args, **kwargs):
return redirect('/AuthUsers')
return auth_users
@app.route('/update/<serial>/<name>',methods=['GET','POST'])
def update_db(serial,name):
cur = mysql.connection.cursor()
cur.execute("SELECT * from users where serial ='" + serial + "' and name ='" + name + "'")
data = cur.fetchone()
if data is None:
return 'Authorization FAILED'
else:
if request.method == 'POST':
userDetails = request.form
serial = userDetails['serial']
name = userDetails['name']
email = userDetails['email']
cur = mysql.connection.cursor()
cur.execute("INSERT INTO users(serial,name, email) VALUES(%s,%s, %s)",(int(serial),name, email))
mysql.connection.commit()
cur.close()
# return redirect('/users')
return "SUCCESSFULLY UPDATED"
return render_template('index.html')
@app.route('/users/<serial>/<name>',methods=['GET','POST'])
def update_users(serial,name):
cur = mysql.connection.cursor()
cur.execute("SELECT * from users where serial ='" + serial + "' and name ='" + name + "'")
data = cur.fetchone()
if data is None:
return 'Authorization FAILED'
else:
resultValue = cur.execute("SELECT * from users")
if resultValue > 0:
userDetails = cur.fetchall()
return render_template('users.html', userDetails=userDetails)
@app.route('/Authenticate', methods=['GET','POST'])
def Authenticate():
if request.method == 'POST':
userDetails = request.form
serial = userDetails['serial']
name = userDetails['name']
return redirect(url_for('update_db',serial=serial,name=name))
return render_template('index1.html')
@app.route('/AuthUsers', methods=['GET','POST'])
def AuthUsers():
if request.method == 'POST':
userDetails = request.form
serial = userDetails['serial']
name = userDetails['name']
return redirect(url_for('update_users',serial=serial,name=name))
return render_template('index1.html')
@app.route('/update', methods=['GET', 'POST'])
@auth_update
def update():
if request.method == 'POST':
pass
return render_template('index.html')
@app.route('/users')
@auth_users
def users():
pass
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port='5000')