-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.py
More file actions
46 lines (33 loc) · 1.76 KB
/
page.py
File metadata and controls
46 lines (33 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from fastapi import APIRouter, Request, HTTPException, Depends, Form
from fastapi.responses import HTMLResponse, RedirectResponse
from sqlalchemy.orm import Session
from database.data import get_db
from database.models.table import Account,Transaction
from connect import templates
pages_router = APIRouter(tags=["Pages"])
# route for home page.
@pages_router.get("/", response_class=HTMLResponse)
async def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
# Endpoint for handling the form submission
@pages_router.post("/login", response_class=HTMLResponse)
async def login(request: Request, name: str = Form(...), surname: str = Form(...), email: str = Form(...), db: Session = Depends(get_db)):
# Check if account exists in the database with the provided name, surname, and email
user = db.query(Account).filter(Account.name == name, Account.surname == surname, Account.email == email).first()
# If account is not found, raise an HTTP exception
if not user:
raise HTTPException(status_code=404, detail="Account not found")
# Redirect to the detail page with the user's account ID
return RedirectResponse(url=f"/detail/{user.id}", status_code=303)
# route for detail page.
@pages_router.get("/detail/{account_id}", response_class=HTMLResponse)
async def details_page(request: Request, account_id: int, db: Session = Depends(get_db)):
user = db.query(Account).filter(Account.id == account_id).first()
if not user:
raise HTTPException(status_code=404, detail="Account not found")
return templates.TemplateResponse("details.html", {"request": request, "account": user})
# Creating account page.
# Updating account page.
# Deleting account page.
# Deposit page.
# Withdraw page.