From 6d3899e8e134cf019d1d444e08db378d7e9ebff0 Mon Sep 17 00:00:00 2001 From: Kirubakaran Date: Sat, 13 Sep 2025 02:08:41 +0530 Subject: [PATCH] feat: added the auth guard script --- backend/__pycache__/models.cpython-313.pyc | Bin 3730 -> 3730 bytes backend/main.py | 6 +++--- frontend/analytics.html | 2 ++ frontend/dashboard.html | 2 ++ frontend/js/auth-guard.js | 11 +++++++++++ frontend/js/auth.js | 2 +- frontend/js/dashboard.js | 4 ++-- frontend/js/logs.js | 4 ++-- frontend/js/station_selection.js | 2 +- frontend/logs.html | 3 +++ frontend/station_selection.html | 6 ++++-- 11 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 frontend/js/auth-guard.js diff --git a/backend/__pycache__/models.cpython-313.pyc b/backend/__pycache__/models.cpython-313.pyc index 1993280a1b70ee5fbd958232d80b157ef2ac0e0a..e56ca323258d3ededb8be21e9904dfaf82a5a598 100644 GIT binary patch delta 20 acmbOvJ4u%NGcPX}0}y=raBw4cJ0Ac(oCb9O delta 20 acmbOvJ4u%NGcPX}0}yPm-@TE$oeuywiUoWC diff --git a/backend/main.py b/backend/main.py index 3a38e8a..f933d25 100644 --- a/backend/main.py +++ b/backend/main.py @@ -38,7 +38,7 @@ app = Flask(__name__) # CORS(app, resources={r"/api/*": {"origins": "http://127.0.0.1:5500"}}, supports_credentials=True, expose_headers='Content-Disposition') -CORS(app, resources={r"/api/*": {"origins": ["http://192.168.1.8:5500","http://127.0.0.1:5500"]}}, supports_credentials=True, expose_headers='Content-Disposition') +CORS(app, resources={r"/api/*": {"origins": ["http://192.168.1.12:5500","http://127.0.0.1:5500"]}}, supports_credentials=True, expose_headers='Content-Disposition') # CORS(app, resources={r"/api/*": {"origins": "http://localhost:5173"}}) , "http://127.0.0.1:5500" # This tells Flask: "For any route starting with /api/, allow requests @@ -484,5 +484,5 @@ if __name__ == '__main__': mqtt_thread = threading.Thread(target=start_mqtt_clients, daemon=True) mqtt_thread.start() - print(f"Starting Flask-SocketIO server on http://192.168.1.8:5000") - socketio.run(app, host='192.168.1.8', port=5000) + print(f"Starting Flask-SocketIO server on http://192.168.1.12:5000") + socketio.run(app, host='192.168.1.12', port=5000) diff --git a/frontend/analytics.html b/frontend/analytics.html index 0dffba5..d0d9bf6 100644 --- a/frontend/analytics.html +++ b/frontend/analytics.html @@ -5,6 +5,8 @@ Swap Station – Analytics + + diff --git a/frontend/dashboard.html b/frontend/dashboard.html index 9d7b595..b9c40e9 100644 --- a/frontend/dashboard.html +++ b/frontend/dashboard.html @@ -5,6 +5,8 @@ Swap Station – Dashboard + + diff --git a/frontend/js/auth-guard.js b/frontend/js/auth-guard.js new file mode 100644 index 0000000..85c78d9 --- /dev/null +++ b/frontend/js/auth-guard.js @@ -0,0 +1,11 @@ +(function() { + // Get the user from localStorage + const user = localStorage.getItem('user'); + + // Check if the user object exists. If not, redirect to the login page. + if (!user) { + // Use window.location.replace() to prevent the user from clicking the "back" button + // and re-accessing the protected page. + window.location.replace('/frontend/index.html'); + } +})(); \ No newline at end of file diff --git a/frontend/js/auth.js b/frontend/js/auth.js index 9fbbc64..065cc38 100644 --- a/frontend/js/auth.js +++ b/frontend/js/auth.js @@ -11,7 +11,7 @@ document.addEventListener('DOMContentLoaded', () => { const password = document.getElementById('password').value; try { - const response = await fetch('http://192.168.1.8:5000/api/login', { + const response = await fetch('http://192.168.1.12:5000/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }), diff --git a/frontend/js/dashboard.js b/frontend/js/dashboard.js index 0d744b2..cb94596 100644 --- a/frontend/js/dashboard.js +++ b/frontend/js/dashboard.js @@ -1,7 +1,7 @@ document.addEventListener('DOMContentLoaded', () => { // --- CONFIGURATION --- - const SOCKET_URL = "http://192.168.1.8:5000"; - const API_BASE = "http://192.168.1.8:5000/api"; // Added for API calls + const SOCKET_URL = "http://192.168.1.12:5000"; + const API_BASE = "http://192.168.1.12:5000/api"; // Added for API calls // --- DOM ELEMENT REFERENCES --- const grid = document.getElementById('chambersGrid'); diff --git a/frontend/js/logs.js b/frontend/js/logs.js index 8d3512f..81cfab9 100644 --- a/frontend/js/logs.js +++ b/frontend/js/logs.js @@ -1,7 +1,7 @@ document.addEventListener('DOMContentLoaded', () => { // --- CONFIGURATION --- - const SOCKET_URL = "http://192.168.1.8:5000"; - const API_BASE = "http://192.168.1.8:5000/api"; + const SOCKET_URL = "http://192.168.1.12:5000"; + const API_BASE = "http://192.168.1.12:5000/api"; // --- DOM ELEMENT REFERENCES --- const stationNameEl = document.getElementById('station-name'); diff --git a/frontend/js/station_selection.js b/frontend/js/station_selection.js index fff3eb6..eb1d47b 100644 --- a/frontend/js/station_selection.js +++ b/frontend/js/station_selection.js @@ -86,7 +86,7 @@ document.addEventListener('DOMContentLoaded', () => { // --- DATA FETCHING & STATUS POLLING --- const loadAndPollStations = async () => { try { - const response = await fetch('http://192.168.1.8:5000/api/stations'); + const response = await fetch('http://192.168.1.12:5000/api/stations'); if (!response.ok) throw new Error('Failed to fetch stations'); const stations = await response.json(); diff --git a/frontend/logs.html b/frontend/logs.html index f6a3aac..df80f5c 100644 --- a/frontend/logs.html +++ b/frontend/logs.html @@ -5,10 +5,13 @@ Swap Station – Logs + + + + @@ -195,7 +197,7 @@