Added: Dashboard html file and routing
This commit is contained in:
3
auth.py
3
auth.py
@@ -102,6 +102,9 @@ async def auth_twitch_callback(code: str, state: str, request: Request, db: Sess
|
||||
|
||||
db.commit()
|
||||
|
||||
# Create a session for the user by storing their database ID.
|
||||
request.session['user_id'] = user.id
|
||||
|
||||
# Redirect to a future dashboard page for a better user experience
|
||||
# This prepares us for Task 1.4 (Session Management) and Task 2.1 (Dashboard UI)
|
||||
return RedirectResponse(url="/dashboard")
|
||||
18
main.py
18
main.py
@@ -2,7 +2,7 @@ import os
|
||||
from fastapi import FastAPI
|
||||
from starlette.middleware.sessions import SessionMiddleware
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from starlette.responses import FileResponse
|
||||
from starlette.responses import FileResponse, RedirectResponse
|
||||
|
||||
import models
|
||||
from database import engine
|
||||
@@ -33,4 +33,18 @@ app.add_middleware(SessionMiddleware, secret_key=settings.ENCRYPTION_KEY)
|
||||
|
||||
@app.get("/")
|
||||
async def read_root():
|
||||
return FileResponse(os.path.join(STATIC_DIR, "login.html"))
|
||||
return FileResponse(os.path.join(STATIC_DIR, "login.html"))
|
||||
|
||||
@app.get("/dashboard")
|
||||
async def read_dashboard(request: Request):
|
||||
# This is our protected route. It checks if a user_id exists in the session.
|
||||
if not request.session.get('user_id'):
|
||||
# If not, redirect them to the login page.
|
||||
return RedirectResponse(url="/")
|
||||
return FileResponse(os.path.join(STATIC_DIR, "dashboard.html"))
|
||||
|
||||
@app.get("/logout")
|
||||
async def logout(request: Request):
|
||||
# Clear the session cookie
|
||||
request.session.clear()
|
||||
return RedirectResponse(url="/")
|
||||
20
static/dashboard.html
Normal file
20
static/dashboard.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Dashboard - MultiChatOverlay</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f0f2f5; margin: 0; }
|
||||
.dashboard-container { text-align: center; padding: 40px; background-color: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
|
||||
a { color: #9146FF; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="dashboard-container">
|
||||
<h1>Dashboard</h1>
|
||||
<p>Welcome! You are successfully logged in.</p>
|
||||
<p><a href="/logout">Logout</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user