forked from monarimartina/eMOTIONS.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
90 lines (72 loc) · 2.92 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
from flask import Flask, render_template, request, redirect, url_for, session
import mysql.connector
app = Flask(__name__, static_folder='website/static', template_folder='website/templates')
app.secret_key = 'your_secret_key'
# MySQL connection configuration
mysql_config = {
'host': 'cs1.ucc.ie',
'user': 'facialrecognition2024',
'password': 'caipu',
'database': 'facialrecognition2024'
}
@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'POST':
username = request.form['username']
email = request.form['email']
password = request.form['password']
try:
connection = mysql.connector.connect(**mysql_config)
cursor = connection.cursor()
# Check if user already exists
cursor.execute("SELECT * FROM users WHERE username = %s", (username,))
if cursor.fetchone():
return "User already exists! Please choose a different username."
# Insert new user into the database
cursor.execute("INSERT INTO users (username, email, password) VALUES (%s, %s, %s)", (username, email, password))
connection.commit()
cursor.close()
connection.close()
return redirect(url_for('login'))
except mysql.connector.Error as e:
return f"Error: {e}"
return render_template('register')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
try:
connection = mysql.connector.connect(**mysql_config)
cursor = connection.cursor()
# Check if username and password match
cursor.execute("SELECT * FROM users WHERE username = %s AND password = %s", (username, password))
user = cursor.fetchone()
cursor.close()
connection.close()
if user:
session['username'] = username
return redirect('https://emotions-dashboard.upwardsdesignstudio.com')
else:
return "Incorrect username or password."
except mysql.connector.Error as e:
return f"Error: {e}"
return render_template('login')
@app.route('/')
@app.route('/index')
def index():
if 'username' in session:
return render_template('index', username=session['username'])
else:
return redirect(url_for('login'))
@app.route('/about')
def about():
return render_template('about')
@app.route('/service')
def service():
return render_template('service')
@app.route('/contact')
def contact():
return render_template('contact')
if __name__ == '__main__':
app.run(debug=True)