Dashboard: Changed stylesheet and started prepping html for population.
This commit is contained in:
18
main.py
18
main.py
@@ -1,8 +1,9 @@
|
||||
import os
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi import FastAPI, Request, Depends
|
||||
from starlette.middleware.sessions import SessionMiddleware
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from starlette.responses import FileResponse, RedirectResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import models
|
||||
@@ -14,6 +15,7 @@ from config import settings # Import settings to get the secret key
|
||||
# Get the absolute path of the directory where this file is located
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
STATIC_DIR = os.path.join(BASE_DIR, "static")
|
||||
TEMPLATES_DIR = os.path.join(BASE_DIR, "templates")
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
@@ -26,6 +28,9 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
# Configure Jinja2 templates
|
||||
templates = Jinja2Templates(directory=TEMPLATES_DIR)
|
||||
|
||||
# Mount the 'static' directory using an absolute path for reliability
|
||||
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
||||
|
||||
@@ -41,12 +46,17 @@ async def read_root():
|
||||
return FileResponse(os.path.join(STATIC_DIR, "login.html"))
|
||||
|
||||
@app.get("/dashboard")
|
||||
async def read_dashboard(request: Request):
|
||||
async def read_dashboard(request: Request, db: Session = Depends(auth.get_db)):
|
||||
# This is our protected route. It checks if a user_id exists in the session.
|
||||
if not request.session.get('user_id'):
|
||||
user_id = request.session.get('user_id')
|
||||
if not user_id:
|
||||
# If not, redirect them to the login page.
|
||||
return RedirectResponse(url="/")
|
||||
return FileResponse(os.path.join(STATIC_DIR, "dashboard.html"))
|
||||
|
||||
user = db.query(models.User).filter(models.User.id == user_id).first()
|
||||
overlay_url = f"{settings.APP_BASE_URL}/overlay/{user.id}"
|
||||
|
||||
return templates.TemplateResponse("dashboard.html", {"request": request, "user": user, "overlay_url": overlay_url})
|
||||
|
||||
@app.get("/logout")
|
||||
async def logout(request: Request):
|
||||
|
||||
Reference in New Issue
Block a user