mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 09:17:06 +08:00
perf: Login api entrypt password
This commit is contained in:
@@ -3,6 +3,7 @@ from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
from apps.system.schemas.system_schema import BaseUserDTO
|
||||
from common.core.deps import SessionDep, Trans
|
||||
from common.utils.crypto import sqlbot_decrypt
|
||||
from ..crud.user import authenticate
|
||||
from common.core.security import create_access_token
|
||||
from datetime import timedelta
|
||||
@@ -11,12 +12,14 @@ from common.core.schemas import Token
|
||||
router = APIRouter(tags=["login"], prefix="/login")
|
||||
|
||||
@router.post("/access-token")
|
||||
def local_login(
|
||||
async def local_login(
|
||||
session: SessionDep,
|
||||
trans: Trans,
|
||||
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
|
||||
) -> Token:
|
||||
user: BaseUserDTO = authenticate(session=session, account=form_data.username, password=form_data.password)
|
||||
origin_account = await sqlbot_decrypt(form_data.username)
|
||||
origin_pwd = await sqlbot_decrypt(form_data.password)
|
||||
user: BaseUserDTO = authenticate(session=session, account=origin_account, password=origin_pwd)
|
||||
if not user:
|
||||
raise HTTPException(status_code=400, detail=trans('i18n_login.account_pwd_error'))
|
||||
if not user.oid or user.oid == 0:
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from sqlbot_xpack.core import sqlbot_decrypt as xpack_sqlbot_decrypt
|
||||
|
||||
async def sqlbot_decrypt(text: str) -> str:
|
||||
return await xpack_sqlbot_decrypt(text)
|
||||
@@ -29,6 +29,7 @@ async def lifespan(app: FastAPI):
|
||||
init_sqlbot_cache()
|
||||
init_dynamic_cors(app)
|
||||
SQLBotLogUtil.info("✅ SQLBot 初始化完成")
|
||||
await sqlbot_xpack.core.clean_xpack_cache()
|
||||
yield
|
||||
SQLBotLogUtil.info("SQLBot 应用关闭")
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ dependencies = [
|
||||
"pyyaml (>=6.0.2,<7.0.0)",
|
||||
"fastapi-mcp (>=0.3.4,<0.4.0)",
|
||||
"tabulate>=0.9.0",
|
||||
"sqlbot-xpack==0.0.3.8",
|
||||
"sqlbot-xpack==0.0.3.9",
|
||||
"fastapi-cache2>=0.2.2",
|
||||
"sqlparse>=0.5.3",
|
||||
"redis>=6.2.0",
|
||||
|
||||
Reference in New Issue
Block a user