-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp9.py
80 lines (68 loc) · 2.57 KB
/
app9.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
#!/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
@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('/update', methods=['GET', 'POST'])
@auth_update
def update():
if request.method == 'POST':
pass
return render_template('index.html')
@app.route('/users')
def users():
cur = mysql.connection.cursor()
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']
cursor = mysql.connection.cursor()
cursor.execute("SELECT * from users where serial ='" + serial + "' and name ='" + name + "'")
data = cursor.fetchone()
if data is None:
return index()
else:
return redirect(url_for('update_db',serial=serial,name=name))
return render_template('index1.html')
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port='5000')