Skip to content

Commit a37ada1

Browse files
committed
fix: Unable to log in with Chinese username
1 parent 9faebd8 commit a37ada1

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

ui/src/views/login/index.vue

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
</div>
8181
</div>
8282
<div v-if="showQrCodeTab">
83-
<QrCodeTab :tabs="orgOptions" :default-tab="defaultQrTab"/>
83+
<QrCodeTab :tabs="orgOptions" :default-tab="defaultQrTab" />
8484
</div>
8585
<div class="login-gradient-divider lighter mt-24" v-if="modeList.length > 1">
8686
<span>{{ $t('views.login.moreMethod') }}</span>
@@ -99,7 +99,7 @@
9999
'font-size': item === 'OAUTH2' ? '8px' : '10px',
100100
color: theme.themeInfo?.theme,
101101
}"
102-
>{{ item }}</span
102+
>{{ item }}</span
103103
>
104104
</el-button>
105105
<el-button
@@ -109,7 +109,7 @@
109109
class="login-button-circle color-secondary"
110110
@click="changeMode('QR_CODE')"
111111
>
112-
<img src="@/assets/icon_qr_outlined.svg" width="25px"/>
112+
<img src="@/assets/icon_qr_outlined.svg" width="25px" />
113113
</el-button>
114114
<el-button
115115
v-if="item === '' && loginMode !== ''"
@@ -126,26 +126,26 @@
126126
</login-layout>
127127
</template>
128128
<script setup lang="ts">
129-
import {computed, onBeforeMount, onMounted, ref} from 'vue'
130-
import {useRoute, useRouter} from 'vue-router'
131-
import type {FormInstance, FormRules} from 'element-plus'
132-
import type {LoginRequest} from '@/api/type/login'
129+
import { computed, onBeforeMount, onMounted, ref } from 'vue'
130+
import { useRoute, useRouter } from 'vue-router'
131+
import type { FormInstance, FormRules } from 'element-plus'
132+
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 {getBrowserLang, t} from '@/locales'
137+
import { getBrowserLang, t } from '@/locales'
138138
import useStore from '@/stores'
139-
import {useI18n} from 'vue-i18n'
139+
import { useI18n } from 'vue-i18n'
140140
import QrCodeTab from '@/views/login/scanCompinents/QrCodeTab.vue'
141-
import {MsgConfirm, MsgError} from '@/utils/message.ts'
141+
import { MsgConfirm, MsgError } from '@/utils/message.ts'
142142
import * as dd from 'dingtalk-jsapi'
143-
import {loadScript} from '@/utils/common'
144-
import forge from 'node-forge';
143+
import { loadScript } from '@/utils/common'
144+
import forge from 'node-forge'
145145
146146
const router = useRouter()
147-
const {login, user, theme} = useStore()
148-
const {locale} = useI18n({useScope: 'global'})
147+
const { login, user, theme } = useStore()
148+
const { locale } = useI18n({ useScope: 'global' })
149149
const loading = ref<boolean>(false)
150150
const route = useRoute()
151151
const identifyCode = ref<string>('')
@@ -194,21 +194,24 @@ const loginHandle = () => {
194194
.asyncLdapLogin(loginForm.value)
195195
.then(() => {
196196
locale.value = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
197-
router.push({name: 'home'})
197+
router.push({ name: 'home' })
198198
})
199199
.catch(() => {
200200
loading.value = false
201201
})
202202
} else {
203-
const publicKey = forge.pki.publicKeyFromPem(user.rasKey);
204-
const encrypted = publicKey.encrypt(JSON.stringify(loginForm.value), 'RSAES-PKCS1-V1_5');
205-
const encryptedBase64 = forge.util.encode64(encrypted);
203+
const publicKey = forge.pki.publicKeyFromPem(user.rasKey)
204+
const encrypted = publicKey.encrypt(
205+
forge.util.encodeUtf8(JSON.stringify(loginForm.value)),
206+
'RSAES-PKCS1-V1_5',
207+
)
208+
const encryptedBase64 = forge.util.encode64(encrypted)
206209
login
207-
.asyncLogin({encryptedData: encryptedBase64, username: loginForm.value.username})
210+
.asyncLogin({ encryptedData: encryptedBase64, username: loginForm.value.username })
208211
.then(() => {
209212
locale.value = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
210213
localStorage.setItem('workspace_id', 'default')
211-
router.push({name: 'home'})
214+
router.push({ name: 'home' })
212215
})
213216
.catch(() => {
214217
const username = loginForm.value.username
@@ -221,13 +224,16 @@ const loginHandle = () => {
221224
}
222225
223226
function makeCode(username?: string) {
224-
loginApi.getCaptcha(username).then((res: any) => {
225-
if (res && res.data && res.data.captcha) {
226-
identifyCode.value = res.data.captcha
227-
}
228-
}).catch((error) => {
229-
console.error('Failed to get captcha:', error)
230-
})
227+
loginApi
228+
.getCaptcha(username)
229+
.then((res: any) => {
230+
if (res && res.data && res.data.captcha) {
231+
identifyCode.value = res.data.captcha
232+
}
233+
})
234+
.catch((error) => {
235+
console.error('Failed to get captcha:', error)
236+
})
231237
}
232238
233239
function handleUsernameBlur(username: string) {
@@ -240,7 +246,7 @@ onBeforeMount(() => {
240246
if (user.isPE() || user.isEE()) {
241247
authApi.getLoginAuthSetting().then((res) => {
242248
if (Object.keys(res.data).length > 0) {
243-
authSetting.value = res.data;
249+
authSetting.value = res.data
244250
} else {
245251
authSetting.value = {
246252
max_attempts: 1,
@@ -339,8 +345,7 @@ function redirectAuth(authType: string, needMessage: boolean = true) {
339345
.then(() => {
340346
window.location.href = url
341347
})
342-
.catch(() => {
343-
})
348+
.catch(() => {})
344349
} else {
345350
console.log('url', url)
346351
window.location.href = url
@@ -418,10 +423,10 @@ onMounted(() => {
418423
const handleDingTalk = () => {
419424
const code = params.get('corpId')
420425
if (code) {
421-
dd.runtime.permission.requestAuthCode({corpId: code}).then((res) => {
426+
dd.runtime.permission.requestAuthCode({ corpId: code }).then((res) => {
422427
console.log('DingTalk client request success:', res)
423428
login.dingOauth2Callback(res.code).then(() => {
424-
router.push({name: 'home'})
429+
router.push({ name: 'home' })
425430
})
426431
})
427432
}
@@ -434,7 +439,7 @@ onMounted(() => {
434439
appId: appId,
435440
success: (res: any) => {
436441
login.larkCallback(res.code).then(() => {
437-
router.push({name: 'home'})
442+
router.push({ name: 'home' })
438443
})
439444
},
440445
fail: (error: any) => {
@@ -454,11 +459,11 @@ onMounted(() => {
454459
scopeList: [],
455460
success: (res: any) => {
456461
login.larkCallback(res.code).then(() => {
457-
router.push({name: 'home'})
462+
router.push({ name: 'home' })
458463
})
459464
},
460465
fail: (error: any) => {
461-
const {errno} = error
466+
const { errno } = error
462467
if (errno === 103) {
463468
callRequestAuthCode()
464469
}

0 commit comments

Comments
 (0)