为了绿色勾勾!
This commit is contained in:
parent
1d3c024b35
commit
f5687c40ac
@ -3,7 +3,7 @@
|
|||||||
# @Author : 河瞬
|
# @Author : 河瞬
|
||||||
# @FileName: manage_user.py
|
# @FileName: manage_user.py
|
||||||
# @Software: PyCharm
|
# @Software: PyCharm
|
||||||
from fastapi import HTTPException, APIRouter, Depends, Request
|
from fastapi import HTTPException, APIRouter, Depends
|
||||||
from sqlmodel import select
|
from sqlmodel import select
|
||||||
|
|
||||||
from dependencies import SessionDep, get_current_user
|
from dependencies import SessionDep, get_current_user
|
||||||
@ -14,7 +14,7 @@ router = APIRouter()
|
|||||||
|
|
||||||
# 枚举成员
|
# 枚举成员
|
||||||
@router.get("/api/s1/user")
|
@router.get("/api/s1/user")
|
||||||
async def list_users(request: Request, session: SessionDep, current_user: User = Depends(get_current_user)):
|
async def list_users(session: SessionDep, current_user: User = Depends(get_current_user)):
|
||||||
if current_user.role != 1:
|
if current_user.role != 1:
|
||||||
raise HTTPException(status_code=403, detail="Only admin users can list users")
|
raise HTTPException(status_code=403, detail="Only admin users can list users")
|
||||||
|
|
||||||
|
|||||||
@ -14,5 +14,6 @@ class Settings(BaseSettings):
|
|||||||
class Config:
|
class Config:
|
||||||
env_file = ".env"
|
env_file = ".env"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(Settings().ALGORITHM)
|
print(Settings().ALGORITHM)
|
||||||
4
main.py
4
main.py
@ -22,10 +22,12 @@ async def lifespan(app: FastAPI):
|
|||||||
|
|
||||||
app = FastAPI(lifespan=lifespan)
|
app = FastAPI(lifespan=lifespan)
|
||||||
|
|
||||||
|
# noinspection PyTypeChecker
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
# allow_origins=["*"],
|
# allow_origins=["*"],
|
||||||
allow_origins=["http://localhost:8080","http://localhost:5000"], # 允许所有来源,也可以指定具体的来源,例如 ["http://example.com", "https://example.com"]
|
allow_origins=["http://localhost:8080", "http://localhost:5000"],
|
||||||
|
# 允许所有来源,也可以指定具体的来源,例如 ["http://example.com", "https://example.com"]
|
||||||
allow_credentials=True, # 允许携带凭证(如cookies)
|
allow_credentials=True, # 允许携带凭证(如cookies)
|
||||||
allow_methods=["*"], # 允许所有方法,也可以指定具体的方法,例如 ["GET", "POST", "PUT", "DELETE"]
|
allow_methods=["*"], # 允许所有方法,也可以指定具体的方法,例如 ["GET", "POST", "PUT", "DELETE"]
|
||||||
allow_headers=["*"], # 允许所有头部,也可以指定具体的头部,例如 ["Content-Type", "Authorization"]
|
allow_headers=["*"], # 允许所有头部,也可以指定具体的头部,例如 ["Content-Type", "Authorization"]
|
||||||
|
|||||||
@ -18,7 +18,7 @@ def create_db_and_tables():
|
|||||||
|
|
||||||
# 创建一个测试客户端
|
# 创建一个测试客户端
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
session: Session = None
|
session: Session | None = None
|
||||||
|
|
||||||
|
|
||||||
class TestLoginReg(unittest.TestCase):
|
class TestLoginReg(unittest.TestCase):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user