add login api

This commit is contained in:
lzy
2025-05-26 22:04:35 +08:00
parent 07ea5e1aab
commit 97155afe03
3 changed files with 24 additions and 5 deletions

View File

@@ -520,6 +520,24 @@ async def debug_page():
</html>
""")
from pydantic import BaseModel
# 申明数据model
class LoginRequest(BaseModel):
user_name: str
pass_word: str
code: str = '' # 兼容传了验证码
@app.post("/matagent/login")
async def login(data: LoginRequest):
# 你实际可以加验证码判断,这里略过
if data.user_name == "test" and data.pass_word == "111111":
# 简单生成一个token实际生产用jwt等
token = "fake_token_example"
return {"token": token}
else:
raise HTTPException(status_code=401, detail="用户名或密码错误")
# Example usage
if __name__ == "__main__":
import uvicorn