-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp6.py
59 lines (50 loc) · 1.99 KB
/
app6.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
#!/usr/bin/python
from flask import Flask, request, redirect, render_template
from flask_mysqldb import MySQL
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')
@app.route('/update', methods=['GET', 'POST'])
def update():
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 'SUCCESS'
return redirect('/users')
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 "Logged in successfully"
return render_template('index1.html')
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port='5000')