-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (49 loc) · 1.7 KB
/
main.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
from flask import Flask, render_template, request, redirect, session
import mysql.connector
import os
app = Flask(__name__)
app.secret_key = os.urandom(24)
conn = mysql.connector.connect(host="remotemysql.com", user="TS3Yb6tH00", password="L4tBVtONpX", database="TS3Yb6tH00")
cursor = conn.cursor()
@app.route('/')
def login():
return render_template('login.html')
@app.route('/register')
def about():
return render_template('register.html')
@app.route('/home')
def home():
if 'user_id' in session:
return render_template('home.html')
else:
return redirect('/')
@app.route('/login_validation', methods=['POST'])
def login_validation():
email = request.form.get('email')
password = request.form.get('password')
cursor.execute("""SELECT * FROM `user` WHERE `email` LIKE '{}' AND `password` LIKE '{}'"""
.format(email, password))
users = cursor.fetchall()
if len(users) > 0:
session['user_id'] = users[0][0]
return redirect('/home')
else:
return redirect('/')
@app.route('/add_user', methods=['POST'])
def add_user():
name = request.form.get('uname')
email = request.form.get('uemail')
password = request.form.get('upassword')
cursor.execute("""INSERT INTO `user` (`user_id`,`name`,`email`,`password`) VALUES
(NULL,'{}','{}','{}')""".format(name, email, password))
conn.commit()
cursor.execute("""SELECT * FROM `user` WHERE `email` LIKE '{}'""".format(email))
myuser = cursor.fetchall()
session['user_id'] = myuser[0][0]
return redirect('/home')
@app.route('/logout')
def logout():
session.pop('user_id')
return redirect('/')
if __name__ == "__main__":
app.run(debug=True)