From 4154bd053ebb926e0ea3f9e231e38228dc456727 Mon Sep 17 00:00:00 2001 From: CHARU AWASTHI <148922861+Charu19awasthi@users.noreply.github.com> Date: Sat, 11 Jan 2025 18:48:18 +0530 Subject: [PATCH 1/5] Create FLASK BACKEND,py --- FLASK BACKEND,py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 FLASK BACKEND,py diff --git a/FLASK BACKEND,py b/FLASK BACKEND,py new file mode 100644 index 0000000..4eb9d87 --- /dev/null +++ b/FLASK BACKEND,py @@ -0,0 +1,63 @@ +from flask import Flask, render_template, session, redirect, url_for, request +import mysql.connector + +app = Flask(__name__) +app.secret_key = 'supersecretkey' + +# Connect to MySQL database +def get_db_connection(): + return mysql.connector.connect( + host="localhost", + user="root", + password="yourpassword", + database="finance_data" + ) + +@app.route('/dashboard') +def dashboard(): + if 'user_id' not in session: + return redirect(url_for('login')) + + user_id = session['user_id'] + + connection = get_db_connection() + cursor = connection.cursor(dictionary=True) + + # Fetch user's visualizations + cursor.execute("SELECT * FROM visualizations WHERE user_id = %s", (user_id,)) + visualizations = cursor.fetchall() + + # Fetch user's uploaded data + cursor.execute("SELECT * FROM uploaded_data WHERE user_id = %s", (user_id,)) + uploaded_data = cursor.fetchall() + + cursor.close() + connection.close() + + return render_template('dashboard.html', visualizations=visualizations, uploaded_data=uploaded_data) + +@app.route('/login', methods=['GET', 'POST']) +def login(): + if request.method == 'POST': + username = request.form['username'] + password = request.form['password'] + + # Check credentials (add hash check for security) + connection = get_db_connection() + cursor = connection.cursor(dictionary=True) + cursor.execute("SELECT * FROM user WHERE username = %s AND password = %s", (username, password)) + user = cursor.fetchone() + + cursor.close() + connection.close() + + if user: + session['user_id'] = user['user_id'] + return redirect(url_for('dashboard')) + + return "Invalid credentials", 401 + + return render_template('login.html') + +if __name__ == "__main__": + app.run(debug=True) From 401677fbd76f7dafeb0fbbc3b1929561a6fb7ef3 Mon Sep 17 00:00:00 2001 From: CHARU AWASTHI <148922861+Charu19awasthi@users.noreply.github.com> Date: Sat, 11 Jan 2025 18:49:15 +0530 Subject: [PATCH 2/5] Create dashboard.html --- dashboard.html | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 dashboard.html diff --git a/dashboard.html b/dashboard.html new file mode 100644 index 0000000..bee6ea1 --- /dev/null +++ b/dashboard.html @@ -0,0 +1,32 @@ + + +
+ + +