diff --git a/.env.template b/.env.template index 088b236..fad74fd 100644 --- a/.env.template +++ b/.env.template @@ -1,5 +1,6 @@ DB_URL=mssql+pyodbc://{user}:{password}@{host}/{database_name}?driver=ODBC+Driver+17+for+SQL+Server HOST=0.0.0.0 PORT=4444 -SERVER_ROOT= -PREFIX=/agree \ No newline at end of file +SERVER_ROOT=/lk/agreement +PREFIX= +URL=https://api.jkhsakha.ru \ No newline at end of file diff --git a/main.py b/main.py index e2d7642..d85df99 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,8 @@ -from fastapi import FastAPI, APIRouter, Request, HTTPException +from fastapi import FastAPI, APIRouter, Request, HTTPException,Depends from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import ORJSONResponse, HTMLResponse +from aiohttp import ClientSession +from fastapi.security import OAuth2PasswordBearer from sqlmodel import create_engine, Field, SQLModel, UUID, DateTime, func, Column, text, bindparam from sqlalchemy.dialects.mssql import UNIQUEIDENTIFIER, DATETIME from sqlalchemy import insert @@ -12,7 +14,8 @@ import os load_dotenv() DB_URL = os.getenv("DB_URL") SERVER_ROOT = os.getenv("SERVER_ROOT") -PREFIX = os.getenv("PREFIX") +PREFIX = (SERVER_ROOT if SERVER_ROOT else "") +os.getenv("PREFIX") +URL = os.getenv("URL") db_engine = create_engine(DB_URL) class Agreement(SQLModel,table=True): @@ -46,32 +49,30 @@ app.add_middleware( allow_headers=["*"], ) +async def get_current_user(data: str = Depends(OAuth2PasswordBearer(tokenUrl=f"{URL}/auth/login/"))): + import json + async with ClientSession() as session: + response = await session.get(f"{URL}/auth/get_current_user/{data}") + data = await response.read() + return json.loads(data) + router = APIRouter( - prefix=PREFIX + prefix=PREFIX, + dependencies=[Depends(get_current_user)] ) -@app.get("/", response_class= HTMLResponse) -async def hello(request: Request): - return """ - -
-