Spaces:
Runtime error
Implement proper demo authentication flow
Browse filesAUTHENTICATION FLOW:
- All pages redirect to /login when no user is authenticated
- Root /, /form, /map, /welcome all require login first
- Demo account auto-logs in without password prompt
- After demo login, redirect to /welcome screen
- Demo user then navigates through welcome β form/map
ROUTE UPDATES:
- / β /login (if not authenticated)
- /form β /login (if not authenticated)
- /map β /login (if not authenticated)
- /welcome β /login (if not authenticated)
- Demo users: login β /welcome β form/map exploration
DEMO LOGIN FLOW:
1. Visitor goes to any page β redirected to /login
2. Ishita clicks 'Demo Account' β auto-logs in
3. Redirected to /welcome screen
4. Welcome buttons work with authenticated demo user
5. Full exploration available
Result: Secure, consistent authentication flow for demo presentation
- app.py +14 -10
- static/index.html +2 -2
- static/login.html +2 -2
- static/map.html +2 -2
- static/sw.js +1 -1
- version.json +1 -1
|
@@ -464,8 +464,12 @@ async def get_user_info(user: Dict[str, Any] = Depends(require_auth)):
|
|
| 464 |
|
| 465 |
# Frontend routes
|
| 466 |
@app.get("/welcome", response_class=HTMLResponse, tags=["Frontend"])
|
| 467 |
-
async def serve_welcome():
|
| 468 |
-
"""Serve the
|
|
|
|
|
|
|
|
|
|
|
|
|
| 469 |
try:
|
| 470 |
with open("static/welcome.html", encoding="utf-8") as f:
|
| 471 |
content = f.read()
|
|
@@ -487,14 +491,14 @@ async def serve_login():
|
|
| 487 |
|
| 488 |
@app.get("/", response_class=HTMLResponse, tags=["Frontend"])
|
| 489 |
async def read_root(request: Request):
|
| 490 |
-
"""Serve main app or redirect
|
| 491 |
user = get_current_user(request)
|
| 492 |
|
| 493 |
-
# No user?
|
| 494 |
if not user:
|
| 495 |
-
return RedirectResponse(url="/
|
| 496 |
|
| 497 |
-
# Demo users
|
| 498 |
if user.get('role') == 'demo_user':
|
| 499 |
return RedirectResponse(url="/welcome")
|
| 500 |
|
|
@@ -508,10 +512,10 @@ async def read_root(request: Request):
|
|
| 508 |
|
| 509 |
@app.get("/form", response_class=HTMLResponse, tags=["Frontend"])
|
| 510 |
async def serve_form(request: Request):
|
| 511 |
-
"""Direct access to form for
|
| 512 |
user = get_current_user(request)
|
| 513 |
if not user:
|
| 514 |
-
return RedirectResponse(url="/
|
| 515 |
|
| 516 |
try:
|
| 517 |
with open("static/index.html", encoding="utf-8") as f:
|
|
@@ -526,9 +530,9 @@ async def serve_map(request: Request):
|
|
| 526 |
# Check if user is authenticated
|
| 527 |
user = get_current_user(request)
|
| 528 |
|
| 529 |
-
#
|
| 530 |
if not user:
|
| 531 |
-
return RedirectResponse(url="/
|
| 532 |
|
| 533 |
return RedirectResponse(url="/static/map.html")
|
| 534 |
|
|
|
|
| 464 |
|
| 465 |
# Frontend routes
|
| 466 |
@app.get("/welcome", response_class=HTMLResponse, tags=["Frontend"])
|
| 467 |
+
async def serve_welcome(request: Request):
|
| 468 |
+
"""Serve the demo welcome screen for authenticated users"""
|
| 469 |
+
user = get_current_user(request)
|
| 470 |
+
if not user:
|
| 471 |
+
return RedirectResponse(url="/login")
|
| 472 |
+
|
| 473 |
try:
|
| 474 |
with open("static/welcome.html", encoding="utf-8") as f:
|
| 475 |
content = f.read()
|
|
|
|
| 491 |
|
| 492 |
@app.get("/", response_class=HTMLResponse, tags=["Frontend"])
|
| 493 |
async def read_root(request: Request):
|
| 494 |
+
"""Serve main app or redirect based on user type"""
|
| 495 |
user = get_current_user(request)
|
| 496 |
|
| 497 |
+
# No user? Redirect to login
|
| 498 |
if not user:
|
| 499 |
+
return RedirectResponse(url="/login")
|
| 500 |
|
| 501 |
+
# Demo users see welcome screen after login
|
| 502 |
if user.get('role') == 'demo_user':
|
| 503 |
return RedirectResponse(url="/welcome")
|
| 504 |
|
|
|
|
| 512 |
|
| 513 |
@app.get("/form", response_class=HTMLResponse, tags=["Frontend"])
|
| 514 |
async def serve_form(request: Request):
|
| 515 |
+
"""Direct access to form for demo users"""
|
| 516 |
user = get_current_user(request)
|
| 517 |
if not user:
|
| 518 |
+
return RedirectResponse(url="/login")
|
| 519 |
|
| 520 |
try:
|
| 521 |
with open("static/index.html", encoding="utf-8") as f:
|
|
|
|
| 530 |
# Check if user is authenticated
|
| 531 |
user = get_current_user(request)
|
| 532 |
|
| 533 |
+
# Redirect to login if not authenticated
|
| 534 |
if not user:
|
| 535 |
+
return RedirectResponse(url="/login")
|
| 536 |
|
| 537 |
return RedirectResponse(url="/static/map.html")
|
| 538 |
|
|
@@ -953,7 +953,7 @@
|
|
| 953 |
// Force refresh if we detect cached version
|
| 954 |
(function() {
|
| 955 |
const currentVersion = '5.1.1';
|
| 956 |
-
const timestamp = '
|
| 957 |
const lastVersion = sessionStorage.getItem('treetrack_version');
|
| 958 |
const lastTimestamp = sessionStorage.getItem('treetrack_timestamp');
|
| 959 |
|
|
@@ -1199,7 +1199,7 @@
|
|
| 1199 |
</div>
|
| 1200 |
</div>
|
| 1201 |
|
| 1202 |
-
<script type="module" src="/static/js/tree-track-app.js?v=5.1.1&t=
|
| 1203 |
|
| 1204 |
<script>
|
| 1205 |
// Idle-time prefetch of map assets to speed up first navigation
|
|
|
|
| 953 |
// Force refresh if we detect cached version
|
| 954 |
(function() {
|
| 955 |
const currentVersion = '5.1.1';
|
| 956 |
+
const timestamp = '1761486823'; // Cache-busting bump
|
| 957 |
const lastVersion = sessionStorage.getItem('treetrack_version');
|
| 958 |
const lastTimestamp = sessionStorage.getItem('treetrack_timestamp');
|
| 959 |
|
|
|
|
| 1199 |
</div>
|
| 1200 |
</div>
|
| 1201 |
|
| 1202 |
+
<script type="module" src="/static/js/tree-track-app.js?v=5.1.1&t=1761486823"></script>
|
| 1203 |
|
| 1204 |
<script>
|
| 1205 |
// Idle-time prefetch of map assets to speed up first navigation
|
|
@@ -419,9 +419,9 @@
|
|
| 419 |
|
| 420 |
showMessage('Demo access granted! Redirecting...', 'success');
|
| 421 |
|
| 422 |
-
// Redirect to
|
| 423 |
setTimeout(() => {
|
| 424 |
-
window.location.href = '/';
|
| 425 |
}, 1500);
|
| 426 |
} else {
|
| 427 |
throw new Error('Demo mode not available');
|
|
|
|
| 419 |
|
| 420 |
showMessage('Demo access granted! Redirecting...', 'success');
|
| 421 |
|
| 422 |
+
// Redirect to welcome screen for demo users
|
| 423 |
setTimeout(() => {
|
| 424 |
+
window.location.href = '/welcome';
|
| 425 |
}, 1500);
|
| 426 |
} else {
|
| 427 |
throw new Error('Demo mode not available');
|
|
@@ -799,7 +799,7 @@
|
|
| 799 |
// Force refresh if we detect cached version
|
| 800 |
(function() {
|
| 801 |
const currentVersion = '5.1.1';
|
| 802 |
-
const timestamp = '
|
| 803 |
const lastVersion = sessionStorage.getItem('treetrack_version');
|
| 804 |
const lastTimestamp = sessionStorage.getItem('treetrack_timestamp');
|
| 805 |
|
|
@@ -925,7 +925,7 @@ const timestamp = '1761486700'; // Current timestamp for cache busting
|
|
| 925 |
|
| 926 |
<!-- Leaflet JS -->
|
| 927 |
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
| 928 |
-
<script src="/static/map.js?v=5.1.1&t=
|
| 929 |
|
| 930 |
"default-state": {
|
| 931 |
gradients: [
|
|
|
|
| 799 |
// Force refresh if we detect cached version
|
| 800 |
(function() {
|
| 801 |
const currentVersion = '5.1.1';
|
| 802 |
+
const timestamp = '1761486823'; // Current timestamp for cache busting
|
| 803 |
const lastVersion = sessionStorage.getItem('treetrack_version');
|
| 804 |
const lastTimestamp = sessionStorage.getItem('treetrack_timestamp');
|
| 805 |
|
|
|
|
| 925 |
|
| 926 |
<!-- Leaflet JS -->
|
| 927 |
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
| 928 |
+
<script src="/static/map.js?v=5.1.1&t=1761486823">
|
| 929 |
|
| 930 |
"default-state": {
|
| 931 |
gradients: [
|
|
@@ -1,5 +1,5 @@
|
|
| 1 |
// TreeTrack Service Worker - PWA and Offline Support
|
| 2 |
-
const VERSION =
|
| 3 |
const CACHE_NAME = `treetrack-v${VERSION}`;
|
| 4 |
const STATIC_CACHE = `static-v${VERSION}`;
|
| 5 |
const API_CACHE = `api-v${VERSION}`;
|
|
|
|
| 1 |
// TreeTrack Service Worker - PWA and Offline Support
|
| 2 |
+
const VERSION = 1761486823; // Cache busting bump - force clients to fetch new static assets and header image change
|
| 3 |
const CACHE_NAME = `treetrack-v${VERSION}`;
|
| 4 |
const STATIC_CACHE = `static-v${VERSION}`;
|
| 5 |
const API_CACHE = `api-v${VERSION}`;
|
|
@@ -1,4 +1,4 @@
|
|
| 1 |
{
|
| 2 |
"version": "5.1.1",
|
| 3 |
-
"timestamp":
|
| 4 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"version": "5.1.1",
|
| 3 |
+
"timestamp": 1761486823
|
| 4 |
}
|