Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from backend.routers import reports
from backend.utils.database import lifespan
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn

app = FastAPI(
Expand All @@ -25,11 +26,18 @@
def index():
return docs_metadata.index_response

app.include_router(users.router)
app.include_router(auth.router)
app.include_router(projects.router)
app.include_router(scenarios.router)
app.include_router(reports.router)
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(users.router, prefix="/api")
app.include_router(auth.router, prefix="/api")
app.include_router(projects.router, prefix="/api")
app.include_router(scenarios.router, prefix="/api")
app.include_router(reports.router, prefix="/api")

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
2 changes: 1 addition & 1 deletion backend/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
session: SessionDep) -> Token:
"""Authenticate user and return an access token."""
user = session.exec(select(User).where(User.email == form_data.email)).first()
user = session.exec(select(User).where(User.email == form_data.username)).first()
password_to_check = user.hashed_password if user else DUMMY_HASH
password_valid = verify_password(form_data.password, password_to_check)

Expand Down
12 changes: 6 additions & 6 deletions backend/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from fastapi.security import OAuth2PasswordBearer
import os
from pwdlib import PasswordHash
from pydantic import BaseModel
from pydantic import BaseModel, EmailStr
from sqlmodel import Session, select
from typing import Annotated

Expand All @@ -26,7 +26,7 @@ class Token(BaseModel):
token_type: str

class TokenData(BaseModel):
username: str | None = None
email: EmailStr | None = None


def verify_password(plain_password, hashed_password):
Expand Down Expand Up @@ -57,13 +57,13 @@ async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)],
)
try:
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
username = payload.get("sub")
if username is None:
email = payload.get("sub")
if email is None:
raise credentials_exception
token_data = TokenData(username=username)
token_data = TokenData(email=email)
except InvalidTokenError:
raise credentials_exception
user = session.exec(select(User).where(User.username == username)).first()
user = session.exec(select(User).where(User.email == email)).first()
if user is None:
raise credentials_exception
return user
25 changes: 25 additions & 0 deletions frontend/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "base-nova",
"rsc": false,
"tsx": false,
"tailwind": {
"config": "",
"css": "src/index.css",
"baseColor": "zinc",
"cssVariables": true,
"prefix": ""
},
"iconLibrary": "lucide",
"rtl": false,
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"menuColor": "default",
"menuAccent": "subtle",
"registries": {}
}
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html lang="en" class="dark">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
Expand Down
18 changes: 18 additions & 0 deletions frontend/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"checkJs": false
},
"include": ["src"]
}

// {
// "compilerOptions": {
// "baseUrl": ".",
// "paths": {
// "@/*": ["./src/*"]
// }
// }
// }
Loading