-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (47 loc) · 1.53 KB
/
main.py
File metadata and controls
62 lines (47 loc) · 1.53 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from fastapi_users import fastapi_users, FastAPIUsers
from pydantic import Field
from fastapi import FastAPI, Depends
from fastapi.encoders import jsonable_encoder
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi import APIRouter, Request, Depends
from config import DB_HOST, DB_NAME, DB_PASS, DB_PORT, DB_USER
from server.auth import auth_backend
from models.models import food, admins, products
from server.database import User
from server.manager import get_user_manager
from fastapi.middleware.cors import CORSMiddleware
from server.schemas import UserRead, UserCreate, UserUpdate, ProductsRead
app = FastAPI(
title="StrikeEmAll"
)
fastapi_users = FastAPIUsers[User, int](
get_user_manager,
[auth_backend],
)
app.include_router(
fastapi_users.get_auth_router(auth_backend),
prefix="/auth",
tags=["auth"],
)
app.include_router(
fastapi_users.get_users_router(UserRead, UserUpdate),
prefix="/users",
tags=["users"],
)
app.include_router(
fastapi_users.get_register_router(UserRead, UserCreate),
prefix="/auth/jwt",
tags=["auth"],
)
app.include_router(
fastapi_users.get_reset_password_router(),
prefix="/auth",
tags=["auth"],
)
current_user = fastapi_users.current_user()
templates = Jinja2Templates(directory="src\html")
@app.get("/home")
def protected_route(request: Request, user: User = Depends(current_user)):
return templates.TemplateResponse("index.html", {"request": request})