Skip to content

Commit b116e37

Browse files
perf: Login api entrypt password
1 parent a3e3647 commit b116e37

File tree

9 files changed

+30
-17
lines changed

9 files changed

+30
-17
lines changed

backend/apps/system/api/login.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from fastapi.security import OAuth2PasswordRequestForm
44
from apps.system.schemas.system_schema import BaseUserDTO
55
from common.core.deps import SessionDep, Trans
6+
from common.utils.crypto import sqlbot_decrypt
67
from ..crud.user import authenticate
78
from common.core.security import create_access_token
89
from datetime import timedelta
@@ -11,12 +12,14 @@
1112
router = APIRouter(tags=["login"], prefix="/login")
1213

1314
@router.post("/access-token")
14-
def local_login(
15+
async def local_login(
1516
session: SessionDep,
1617
trans: Trans,
1718
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
1819
) -> Token:
19-
user: BaseUserDTO = authenticate(session=session, account=form_data.username, password=form_data.password)
20+
origin_account = await sqlbot_decrypt(form_data.username)
21+
origin_pwd = await sqlbot_decrypt(form_data.password)
22+
user: BaseUserDTO = authenticate(session=session, account=origin_account, password=origin_pwd)
2023
if not user:
2124
raise HTTPException(status_code=400, detail=trans('i18n_login.account_pwd_error'))
2225
if not user.oid or user.oid == 0:

backend/common/utils/crypto.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from sqlbot_xpack.core import sqlbot_decrypt as xpack_sqlbot_decrypt
2+
3+
async def sqlbot_decrypt(text: str) -> str:
4+
return await xpack_sqlbot_decrypt(text)

backend/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ async def lifespan(app: FastAPI):
2929
init_sqlbot_cache()
3030
init_dynamic_cors(app)
3131
SQLBotLogUtil.info("✅ SQLBot 初始化完成")
32+
await sqlbot_xpack.core.clean_xpack_cache()
3233
yield
3334
SQLBotLogUtil.info("SQLBot 应用关闭")
3435

backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies = [
3636
"pyyaml (>=6.0.2,<7.0.0)",
3737
"fastapi-mcp (>=0.3.4,<0.4.0)",
3838
"tabulate>=0.9.0",
39-
"sqlbot-xpack==0.0.3.8",
39+
"sqlbot-xpack==0.0.3.9",
4040
"fastapi-cache2>=0.2.2",
4141
"sqlparse>=0.5.3",
4242
"redis>=6.2.0",

frontend/auto-imports.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export {}
88
declare global {
99
const ElMessage: typeof import('element-plus-secondary/es')['ElMessage']
1010
const ElMessageBox: typeof import('element-plus-secondary/es')['ElMessageBox']
11+
const LicenseGenerator: any
1112
}

frontend/src/api/login.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { request } from '@/utils/request'
2-
32
export const AuthApi = {
4-
login: (credentials: { username: string; password: string }) =>
5-
request.post<{
3+
login: (credentials: { username: string; password: string }) => {
4+
const entryCredentials = {
5+
username: LicenseGenerator.sqlbotEncrypt(credentials.username),
6+
password: LicenseGenerator.sqlbotEncrypt(credentials.password),
7+
}
8+
return request.post<{
69
data: any
710
token: string
8-
}>('/login/access-token', credentials, {
11+
}>('/login/access-token', entryCredentials, {
912
headers: {
1013
'Content-Type': 'application/x-www-form-urlencoded',
1114
},
12-
}),
15+
})
16+
},
1317
logout: () => request.post('/auth/logout'),
1418
info: () => request.get('/user/info'),
1519
}

frontend/src/router/watch.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ const loadXpackStatic = () => {
5050
if (document.getElementById('sqlbot_xpack_static')) {
5151
return Promise.resolve()
5252
}
53-
const url = '/xpack_static/license-generator.umd.js'
53+
const url = `/xpack_static/license-generator.umd.js?t=${Date.now()}`
5454
return new Promise((resolve, reject) => {
5555
request
5656
.loadRemoteScript(url, 'sqlbot_xpack_static', () => {
57-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
58-
// @ts-ignore
5957
LicenseGenerator?.init(import.meta.env.VITE_API_BASE_URL).then(() => {
6058
resolve(true)
6159
})

frontend/src/utils/request.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ class HttpService {
9999
// Skip auth for xpack_static requests
100100
return config
101101
}
102-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
103-
// @ts-ignore
102+
104103
const request_key = LicenseGenerator.generate()
105104
config.headers['X-SQLBOT-KEY'] = request_key
106105

@@ -266,8 +265,6 @@ class HttpService {
266265
heads['X-SQLBOT-ASSISTANT-ONLINE'] = assistantStore.getOnline
267266
}
268267
}
269-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
270-
// @ts-ignore
271268
const request_key = LicenseGenerator.generate()
272269
heads['X-SQLBOT-KEY'] = request_key
273270

frontend/src/views/system/user/User.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@
5151
@selection-change="handleSelectionChange"
5252
>
5353
<el-table-column type="selection" width="55" />
54-
<el-table-column prop="name" :label="$t('user.name')" width="280" />
55-
<el-table-column prop="account" :label="$t('user.account')" width="280" />
54+
<el-table-column prop="name" show-overflow-tooltip :label="$t('user.name')" width="280" />
55+
<el-table-column
56+
prop="account"
57+
show-overflow-tooltip
58+
:label="$t('user.account')"
59+
width="280"
60+
/>
5661
<el-table-column prop="status" :label="$t('user.user_status')" width="180">
5762
<template #default="scope">
5863
<div class="user-status-container" :class="[scope.row.status ? 'active' : 'disabled']">

0 commit comments

Comments
 (0)