Skip to content

Commit 68ce998

Browse files
committed
feat: add username parameter to getCaptcha function and hash password with MD5 during login
1 parent d4bdee1 commit 68ce998

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@wecom/jssdk": "^2.3.1",
2828
"axios": "^1.8.4",
2929
"cropperjs": "^1.6.2",
30+
"crypto-js": "^4.2.0",
3031
"dingtalk-jsapi": "^3.1.0",
3132
"echarts": "^5.6.0",
3233
"element-plus": "^2.10.2",
@@ -60,6 +61,7 @@
6061
},
6162
"devDependencies": {
6263
"@tsconfig/node22": "^22.0.1",
64+
"@types/crypto-js": "^4.2.2",
6365
"@types/file-saver": "^2.0.7",
6466
"@types/node": "^22.14.0",
6567
"@types/nprogress": "^0.2.3",

ui/src/api/chat/chat.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ const ldapLogin: (
112112

113113
/**
114114
* 获取验证码
115+
* @param username
115116
* @param loading 接口加载器
116117
*/
117-
const getCaptcha: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
118-
return get('/captcha', undefined, loading)
118+
const getCaptcha: (username?: string, loading?: Ref<boolean>) => Promise<Result<any>> = (username, loading) => {
119+
return get('/captcha', {username: username}, loading)
119120
}
120121

121122
/**

ui/src/api/type/chat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface ChatProfile {
1111
authentication_type?: 'password' | 'login'
1212
// 登录类型
1313
login_value?: Array<string>
14+
max_attempts?: number
1415
}
1516

1617
interface ChatUserProfile {

ui/src/utils/common.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { nanoid } from 'nanoid'
1+
import {nanoid} from 'nanoid'
2+
23
/**
34
* 数字处理
45
*/
@@ -7,6 +8,7 @@ export function toThousands(num: any) {
78
return n.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
89
})
910
}
11+
1012
export function numberFormat(num: number) {
1113
return num < 1000 ? toThousands(num) : toThousands((num / 1000).toFixed(1)) + 'k'
1214
}
@@ -25,6 +27,7 @@ export function filesize(size: number) {
2527

2628
// 头像
2729
export const defaultIcon = '/${window.MaxKB.prefix}/favicon.ico'
30+
2831
export function isAppIcon(url: string | undefined) {
2932
return url === defaultIcon ? '' : url
3033
}
@@ -65,6 +68,7 @@ export function getImgUrl(name: string) {
6568
: 'unknown'
6669
return new URL(`../assets/fileType/${type}-icon.svg`, import.meta.url).href
6770
}
71+
6872
// 是否是白名单后缀
6973
export function isRightType(name: string, type: string) {
7074
return typeList[type].includes(fileType(name).toLowerCase())
@@ -94,7 +98,7 @@ interface LoadScriptOptions {
9498
}
9599

96100
export const loadScript = (url: string, options: LoadScriptOptions = {}): Promise<void> => {
97-
const { jsId, forceReload = false } = options
101+
const {jsId, forceReload = false} = options
98102
const scriptId = jsId || `script-${btoa(url).slice(0, 12)}` // 生成唯一 ID
99103

100104
return new Promise((resolve, reject) => {
@@ -144,12 +148,14 @@ export function getNormalizedUrl(url: string) {
144148
}
145149
return url
146150
}
151+
147152
export function getFileUrl(fileId?: string) {
148153
if (fileId) {
149154
return `${window.MaxKB.prefix}/oss/file/${fileId}`
150155
}
151156
return ''
152157
}
158+
153159
export const resetUrl = (url: string, defaultUrl?: string) => {
154160
if (url && url.startsWith('./')) {
155161
return `${window.MaxKB.prefix}/${url.substring(2)}`

ui/src/views/chat/user-login/index.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ import QrCodeTab from '@/views/chat/user-login/scanCompinents/QrCodeTab.vue'
180180
import {MsgConfirm, MsgError} from '@/utils/message.ts'
181181
import PasswordAuth from '@/views/chat/auth/component/password.vue'
182182
import {isAppIcon} from '@/utils/common'
183+
import CryptoJS from "crypto-js";
183184
184185
useResize()
185186
const router = useRouter()
@@ -249,6 +250,7 @@ const loginHandle = () => {
249250
})
250251
})
251252
} else {
253+
loginForm.value.password = CryptoJS.MD5(loginForm.value.password.trim()).toString(CryptoJS.enc.Hex)
252254
chatUser.login(loginForm.value).then((ok) => {
253255
router.push({
254256
name: 'chat',

ui/src/views/login/index.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,22 @@
126126
</login-layout>
127127
</template>
128128
<script setup lang="ts">
129-
import {onMounted, ref, onBeforeMount, computed} from 'vue'
129+
import {computed, onBeforeMount, onMounted, ref} from 'vue'
130130
import {useRoute, useRouter} from 'vue-router'
131131
import type {FormInstance, FormRules} from 'element-plus'
132132
import type {LoginRequest} from '@/api/type/login'
133133
import LoginContainer from '@/layout/login-layout/LoginContainer.vue'
134134
import LoginLayout from '@/layout/login-layout/LoginLayout.vue'
135135
import loginApi from '@/api/user/login'
136136
import authApi from '@/api/system-settings/auth-setting'
137-
import {t, getBrowserLang} from '@/locales'
137+
import {getBrowserLang, t} from '@/locales'
138138
import useStore from '@/stores'
139139
import {useI18n} from 'vue-i18n'
140140
import QrCodeTab from '@/views/login/scanCompinents/QrCodeTab.vue'
141141
import {MsgConfirm, MsgError} from '@/utils/message.ts'
142142
import * as dd from 'dingtalk-jsapi'
143143
import {loadScript} from '@/utils/common'
144+
import CryptoJS from 'crypto-js';
144145
145146
const router = useRouter()
146147
const {login, user, theme} = useStore()
@@ -199,6 +200,7 @@ const loginHandle = () => {
199200
loading.value = false
200201
})
201202
} else {
203+
loginForm.value.password = CryptoJS.MD5(loginForm.value.password.trim()).toString(CryptoJS.enc.Hex)
202204
login
203205
.asyncLogin(loginForm.value)
204206
.then(() => {

0 commit comments

Comments
 (0)