-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
111 lines (104 loc) · 4.19 KB
/
app.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
101
102
103
104
105
106
107
108
109
110
111
from flask import *
import sqlite3
connection = sqlite3.connect("login.db")
cursor = connection.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS Emails (
"First Name" text,
"Last Name" text,
Email TEXT,
Password TEXT
)
""")
connection.commit()
connection.close()
app = Flask(__name__,template_folder='templates',static_folder='static')
@app.route("/", methods=['GET','POST'])
def home():
if request.method=='POST':
select=request.form['page']
return redirect(url_for(f'{select}'))
return render_template("home.html")
@app.route("/signup", methods=['GET','POST'])
def signup():
if request.method=='POST':
fname = request.form['fname']
lname=request.form['lname']
email=request.form['email']
pwd1 = request.form['password1']
pwd2 = request.form['password2']
if pwd1 != pwd2:
return render_template("signup.html", pwd="Please Enter Correct Password")
connection = sqlite3.connect("login.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM Emails WHERE Email='{e}'".format(e=email))
search = cursor.fetchone()
if search:
return render_template("signup.html", pwd = "Email is already taken, Please try another E-MAIL")
query1 = "INSERT INTO Emails VALUES('{a}','{b}','{c}','{d}')".format(a=fname, b=lname,c=email, d=pwd1)
connection.execute(query1)
connection.commit()
connection.close()
return redirect(url_for("signup_success",sss=email))
return render_template("signup.html")
@app.route("/login",methods=['GET','POST'])
def login():
if request.method=='POST':
email = request.form['email']
pas = request.form['password']
connection = sqlite3.connect("login.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM Emails WHERE Email = '{e}'".format(e=email))
search = cursor.fetchone()
connection.commit()
connection.close()
if len(search)==0:
return render_template("login.html", pwd="Please Enter Valid Email")
elif pas!=search[3]:
return render_template("login.html",pwd="Please Enter Correct Password")
return redirect(url_for("login_success",pas=email))
return render_template("login.html")
@app.route("/loginsuccess<pas>",methods=['GET','POST'])
def login_success(pas):
if request.method=='GET':
connection = sqlite3.connect("login.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM Emails Where Email = '{e}'".format(e=pas))
search = cursor.fetchone()
connection.commit()
connection.close()
return render_template("loginsuccess.html", name=search[1])
if request.method=='POST':
return redirect(url_for("profile",usr=pas))
return render_template("loginsuccess.html")
@app.route("/signupsuccess<sss>", methods=['GET', 'POST'])
def signup_success(sss):
if request.method=='GET':
connection = sqlite3.connect("login.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM Emails WHERE Email = '{s}'".format(s=sss))
search = cursor.fetchone()
connection.commit()
connection.close()
return render_template("signupsuccess.html",name = search[1])
if request.method=='POST':
return redirect(url_for("profile",usr=sss))
return render_template("signupsuccess.html")
@app.route("/profile<usr>",methods=['GET','POST'])
def profile(usr):
if request.method=='GET':
connection = sqlite3.connect("login.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM Emails WHERE Email = '{s}'".format(s=usr))
search = cursor.fetchone()
connection.commit()
connection.close()
return render_template("profile.html", fname=search[0], lname=search[1], email=search[2], password=search[3])
if request.method=='POST':
return redirect(url_for("home"))
return render_template("profile.html")
@app.route("/username/<name>/<int:number>")
def hello(name,number):
return f"Hello {name} and {number}"
if __name__=="__main__":
app.run(debug=True,port=3000)