-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp7.py
99 lines (86 loc) · 3.41 KB
/
app7.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
#!/usr/bin/python
from flask import Flask, request, redirect, render_template
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 Authenticate(function):
@wraps(function)
# @app.route('/Authenticate', methods=['GET','POST'])
# def wrapper(*args, **kwargs):
def wrapper(a):
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:
a = 1
return function(a)
return render_template('index1.html')
return wrapper
@app.route('/update1/a', methods=['GET', 'POST'])
def update1(a):
if request.method == 'POST' and a == 1:
userDetails1 = request.form
serial1 = userDetails1['serial']
email = userDetails1['email']
name1 = userDetails1['name']
cur = mysql.connection.cursor()
cur.execute("INSERT INTO users(serial,name, email) VALUES(%s,%s, %s)",(int(serial1),name1, email))
mysql.connection.commit()
cur.close()
# return render_template('users.html', userDetails=userDetails)
return render_template('index.html')
@app.route('/update/<int:a>', methods=['GET', 'POST'])
@Authenticate
def update(a):
if request.method == 'POST' and a == 1:
return redirect(url_for('/update1/a')
# return render_template('index.html')
@app.route('/users', methods=['GET','POST'])
def users():
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 "AUTHENTICATION FAILED"
else:
cur = mysql.connection.cursor()
resultValue = cur.execute("SELECT * from users")
if resultValue > 0:
userDetails = cur.fetchall()
return render_template('users.html', userDetails=userDetails)
return render_template('index1.html')
#@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 "Logged in successfully"
# return render_template('index1.html')
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port='5000')