-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
97 lines (69 loc) · 2.31 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
# from cs50 import SQL
import sqlite3
from flask import Flask, flash, redirect, render_template, request, session, url_for
app = Flask(__name__)
conn = sqlite3.connect('databases.db')
cursor = conn.cursor()
# Create the users table if it doesn't exist
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL,
password TEXT NOT NULL
)
''')
# Add user data
users_data = [
('example_user', 'password123'),
('test_user', 'testpassword')
]
cursor.executemany('INSERT INTO users (username, password) VALUES (?, ?)', users_data)
# Commit changes and close the connection
conn.commit()
conn.close()
@app.route("/")
def index():
return render_template("index.html")
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/blocks")
def blocks():
return render_template("blocks.html")
@app.route("/account")
def account():
# Example data for the account page
account_info = {
"username": "example_user",
"email": "[email protected]",
"membership_status": "Active",
}
return render_template("account.html", **account_info)
@app.route('/signin', methods=['GET', 'POST'])
def signin():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
# Check if the provided username and password match the database
cursor.execute('SELECT * FROM users WHERE username=? AND password=?', (username, password))
user_data = cursor.fetchone()
if user_data:
return redirect(url_for('account'))
else:
return "Invalid credentials. Please try again."
return render_template('./sign_in.html')
@app.route('/signup', methods=['GET', 'POST'])
def signup():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
# Insert the new user data into the database
cursor.execute('INSERT INTO users (username, password) VALUES (?, ?)', (username, password))
conn.commit()
return redirect(url_for('signin'))
return render_template('./signup.html')
@app.route("/filter")
def filter():
return render_template("filter.html")
if __name__ == "__main__":
app.run()