-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
96 lines (70 loc) · 2.39 KB
/
app.py
File metadata and controls
96 lines (70 loc) · 2.39 KB
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
from flask import Flask, render_template, request, redirect, url_for
from flask_mysqldb import MySQL
app = Flask(__name__)
# MySQL configurations
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'harsha1'
app.config['MYSQL_PASSWORD'] = 'YES'
app.config['MYSQL_DB'] = 'user_data'
app.config['MYSQL_CURSORCLASS'] = 'DictCursor'
mysql = MySQL(app)
# Function to get a database connection
def get_db_connection():
return mysql.connection
@app.route('/')
def index():
return render_template('login.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/stack')
def stack():
return render_template('stack.html')
@app.route('/queue')
def queue():
return render_template('queue.html')
@app.route('/forgot')
def forgot():
return render_template('forgot.html')
@app.route('/contact', methods=['GET', 'POST'])
def contact():
if request.method == 'POST':
# Get form data
name = request.form['name']
email = request.form['email']
message = request.form['message']
print("Received a message from {name} ({email}): {message}")
return render_template('home.html')
return render_template('contact.html')
@app.route('/login', methods=['POST'])
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute('SELECT * FROM users WHERE username = %s AND password = %s', (username, password))
user = cursor.fetchone()
conn.close()
if user:
return redirect(url_for('home'))
else:
return redirect(url_for('index'))
@app.route('/registration', methods=['GET', 'POST'])
def registration():
if request.method == 'POST':
email = request.form['email']
username = request.form['username']
password = request.form['password']
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute('INSERT INTO users (email, username, password) VALUES (%s, %s, %s)', (email, username, password))
conn.commit()
conn.close()
return redirect(url_for('index'))
return render_template('registration.html')
@app.route('/home')
def home():
return render_template('home.html')
if __name__ == '__main__':
app.run(debug=True)