Skip to content

Commit 20c2d8e

Browse files
committed
fix: enhance password reset functionality with encryption and improve code formatting
1 parent aa3ce83 commit 20c2d8e

3 files changed

Lines changed: 56 additions & 48 deletions

File tree

ui/src/views/chat/embed/component/ChatHistoryDrawer.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import ResetPassword from '@/layout/layout-header/avatar/ResetPassword.vue'
9898
import type { ResetCurrentUserPasswordRequest } from '@/api/type/user'
9999
import chatAPI from '@/api/chat/chat'
100100
import { useRoute, useRouter } from 'vue-router'
101+
import JSEncrypt from 'jsencrypt'
101102
102103
const router = useRouter()
103104
const route = useRoute()
@@ -150,7 +151,12 @@ const openResetPassword = () => {
150151
}
151152
152153
const handleResetPassword = (param: ResetCurrentUserPasswordRequest) => {
153-
chatAPI.resetCurrentPassword(param).then(() => {
154+
const JSEncryptCtor = (JSEncrypt as any)?.default ? (JSEncrypt as any).default : JSEncrypt
155+
const js = new (JSEncryptCtor as any)()
156+
js.setPublicKey(chatUser?.chat_profile?.rsaKey)
157+
const jsonData = JSON.stringify(param)
158+
const encryptedBase64 = js.encrypt(jsonData)
159+
chatAPI.resetCurrentPassword({ encryptedData: encryptedBase64 }).then(() => {
154160
router.push({ name: 'login' })
155161
})
156162
}

ui/src/views/chat/mobile/component/ResetPasswordDrawer.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
</el-input>
3030
</el-form-item>
3131
</el-form>
32-
<el-button type="primary" size="large" class="w-full" @click="resetPassword">{{
33-
$t('aiChat.confirmModification')
34-
}}</el-button>
32+
<el-button type="primary" size="large" class="w-full" @click="resetPassword"
33+
>{{ $t('aiChat.confirmModification') }}
34+
</el-button>
3535
</el-drawer>
3636
</template>
3737

@@ -44,6 +44,7 @@ import useStore from '@/stores'
4444
import chatAPI from '@/api/chat/chat'
4545
import { useRouter } from 'vue-router'
4646
import { MsgSuccess } from '@/utils/message'
47+
import JSEncrypt from 'jsencrypt'
4748
4849
const router = useRouter()
4950
const { chatUser } = useStore()
@@ -100,9 +101,14 @@ const rules = ref<FormRules<ResetCurrentUserPasswordRequest>>({
100101
101102
function resetPassword() {
102103
resetPasswordFormRef.value?.validate().then(() => {
103-
chatAPI.resetCurrentPassword(resetPasswordForm.value).then(() => {
104+
const JSEncryptCtor = (JSEncrypt as any)?.default ? (JSEncrypt as any).default : JSEncrypt
105+
const js = new (JSEncryptCtor as any)()
106+
js.setPublicKey(chatUser?.chat_profile?.rsaKey)
107+
const jsonData = JSON.stringify(resetPasswordForm.value)
108+
const encryptedBase64 = js.encrypt(jsonData)
109+
chatAPI.resetCurrentPassword({ encryptedData: encryptedBase64 }).then(() => {
104110
MsgSuccess(t('common.modifySuccess'))
105-
router.push({name: 'login'})
111+
router.push({ name: 'login' })
106112
})
107113
})
108114
}

ui/src/views/chat/pc/index.vue

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,24 @@
4343
chatUser.chat_profile.authentication_type === 'password'
4444
"
4545
>
46-
<img src="@/assets/user-icon.svg" style="width: 54%" alt=""/>
46+
<img src="@/assets/user-icon.svg" style="width: 54%" alt="" />
4747
</el-avatar>
4848
<el-dropdown v-else trigger="click" type="primary" class="w-full">
4949
<div class="flex align-center">
5050
<el-avatar :size="32">
51-
<img src="@/assets/user-icon.svg" style="width: 54%" alt=""/>
51+
<img src="@/assets/user-icon.svg" style="width: 54%" alt="" />
5252
</el-avatar>
5353
<span v-show="!isPcCollapse" class="ml-8 color-text-primary">{{
54-
chatUser.chatUserProfile?.nick_name
55-
}}</span>
54+
chatUser.chatUserProfile?.nick_name
55+
}}</span>
5656
</div>
5757

5858
<template #dropdown>
5959
<el-dropdown-menu style="min-width: 260px">
6060
<div class="flex align-center p-8">
6161
<div class="mr-8 flex align-center">
6262
<el-avatar :size="40">
63-
<img src="@/assets/user-icon.svg" style="width: 54%" alt=""/>
63+
<img src="@/assets/user-icon.svg" style="width: 54%" alt="" />
6464
</el-avatar>
6565
</div>
6666
<div>
@@ -84,7 +84,7 @@
8484
style="padding-top: 8px; padding-bottom: 8px"
8585
@click="logout"
8686
>
87-
<AppIcon iconName="app-export" class="color-secondary"/>
87+
<AppIcon iconName="app-export" class="color-secondary" />
8888
{{ $t('layout.logout') }}
8989
</el-dropdown-item>
9090
</el-dropdown-menu>
@@ -99,7 +99,7 @@
9999
@click="isPcCollapse = !isPcCollapse"
100100
>
101101
<el-icon>
102-
<component :is="isPcCollapse ? 'ArrowRightBold' : 'ArrowLeftBold'"/>
102+
<component :is="isPcCollapse ? 'ArrowRightBold' : 'ArrowLeftBold'" />
103103
</el-icon>
104104
</el-button>
105105
</div>
@@ -148,13 +148,13 @@
148148
<template #dropdown>
149149
<el-dropdown-menu>
150150
<el-dropdown-item @click="exportMarkdown"
151-
>{{ $t('common.export') }} Markdown</el-dropdown-item
151+
>{{ $t('common.export') }} Markdown</el-dropdown-item
152152
>
153153
<el-dropdown-item @click="exportHTML"
154-
>{{ $t('common.export') }} HTML</el-dropdown-item
154+
>{{ $t('common.export') }} HTML</el-dropdown-item
155155
>
156156
<el-dropdown-item @click="openPDFExport"
157-
>{{ $t('common.export') }} PDF</el-dropdown-item
157+
>{{ $t('common.export') }} PDF</el-dropdown-item
158158
>
159159
</el-dropdown-menu>
160160
</template>
@@ -208,8 +208,8 @@
208208
</span> -->
209209
<span>
210210
<el-button text @click="closeExecutionDetail">
211-
<el-icon size="20"><Close/></el-icon
212-
></el-button>
211+
<el-icon size="20"><Close /></el-icon
212+
></el-button>
213213
</span>
214214
</div>
215215
</div>
@@ -225,7 +225,7 @@
225225
:detail="executionDetail"
226226
:appType="applicationDetail?.type"
227227
/>
228-
<ParagraphDocumentContent :detail="rightPanelDetail" v-else/>
228+
<ParagraphDocumentContent :detail="rightPanelDetail" v-else />
229229
</el-scrollbar>
230230
</div>
231231
</div>
@@ -242,37 +242,34 @@
242242
</template>
243243

244244
<script setup lang="ts">
245-
import {ref, onMounted, nextTick, computed, watch, provide} from 'vue'
246-
import {marked} from 'marked'
247-
import {saveAs} from 'file-saver'
245+
import { ref, onMounted, nextTick, computed, watch, provide } from 'vue'
246+
import { marked } from 'marked'
247+
import { saveAs } from 'file-saver'
248248
import sanitizeHtml from 'sanitize-html'
249249
import chatAPI from '@/api/chat/chat'
250250
import useStore from '@/stores'
251251
import useResize from '@/layout/hooks/useResize'
252-
import {hexToRgba} from '@/utils/theme'
253-
import {useRoute, useRouter} from 'vue-router'
252+
import { hexToRgba } from '@/utils/theme'
253+
import { useRoute, useRouter } from 'vue-router'
254254
import ResetPassword from '@/layout/layout-header/avatar/ResetPassword.vue'
255-
import {t} from '@/locales'
256-
import type {ResetCurrentUserPasswordRequest} from '@/api/type/user'
257-
import ExecutionDetailContent
258-
from '@/components/ai-chat/component/knowledge-source-component/ExecutionDetailContent.vue'
259-
import ParagraphSourceContent
260-
from '@/components/ai-chat/component/knowledge-source-component/ParagraphSourceContent.vue'
261-
import ParagraphDocumentContent
262-
from '@/components/ai-chat/component/knowledge-source-component/ParagraphDocumentContent.vue'
255+
import { t } from '@/locales'
256+
import type { ResetCurrentUserPasswordRequest } from '@/api/type/user'
257+
import ExecutionDetailContent from '@/components/ai-chat/component/knowledge-source-component/ExecutionDetailContent.vue'
258+
import ParagraphSourceContent from '@/components/ai-chat/component/knowledge-source-component/ParagraphSourceContent.vue'
259+
import ParagraphDocumentContent from '@/components/ai-chat/component/knowledge-source-component/ParagraphDocumentContent.vue'
263260
import HistoryPanel from '@/views/chat/component/HistoryPanel.vue'
264-
import {cloneDeep} from 'lodash'
265-
import {getFileUrl} from '@/utils/common'
261+
import { cloneDeep } from 'lodash'
262+
import { getFileUrl } from '@/utils/common'
266263
import PdfExport from '@/components/pdf-export/index.vue'
267-
import JSEncrypt from "jsencrypt";
264+
import JSEncrypt from 'jsencrypt'
268265
269-
const {user} = useStore()
266+
const { user } = useStore()
270267
useResize()
271268
272269
provide('scrollData', loadInfiniteScroll)
273270
provide('chatLogPagination', () => chatLogPagination)
274271
const pdfExportRef = ref<InstanceType<typeof PdfExport>>()
275-
const {common, chatUser} = useStore()
272+
const { common, chatUser } = useStore()
276273
const router = useRouter()
277274
const openPDFExport = () => {
278275
pdfExportRef.value?.open(document.getElementById('chatListId'))
@@ -307,13 +304,13 @@ const openResetPassword = () => {
307304
}
308305
309306
const handleResetPassword = (param: ResetCurrentUserPasswordRequest) => {
310-
const JSEncryptCtor = (JSEncrypt as any)?.default ? (JSEncrypt as any).default : JSEncrypt;
311-
const js = new (JSEncryptCtor as any)();
312-
js.setPublicKey(user.rsaKey);
313-
const jsonData = JSON.stringify(param);
314-
const encryptedBase64 = js.encrypt(jsonData);
315-
chatAPI.resetCurrentPassword({encryptedData: encryptedBase64}).then(() => {
316-
router.push({name: 'login'})
307+
const JSEncryptCtor = (JSEncrypt as any)?.default ? (JSEncrypt as any).default : JSEncrypt
308+
const js = new (JSEncryptCtor as any)()
309+
js.setPublicKey(chatUser?.chat_profile?.rsaKey)
310+
const jsonData = JSON.stringify(param)
311+
const encryptedBase64 = js.encrypt(jsonData)
312+
chatAPI.resetCurrentPassword({ encryptedData: encryptedBase64 }).then(() => {
313+
router.push({ name: 'login' })
317314
})
318315
}
319316
@@ -340,8 +337,7 @@ const applicationDetail = computed({
340337
get: () => {
341338
return props.application_profile
342339
},
343-
set: (v) => {
344-
},
340+
set: (v) => {},
345341
})
346342
347343
const chatLogData = ref<any[]>([])
@@ -522,7 +518,7 @@ async function exportMarkdown(): Promise<void> {
522518
})
523519
.join('\n')
524520
525-
const blob: Blob = new Blob([markdownContent], {type: 'text/markdown;charset=utf-8'})
521+
const blob: Blob = new Blob([markdownContent], { type: 'text/markdown;charset=utf-8' })
526522
saveAs(blob, suggestedName)
527523
}
528524
@@ -586,7 +582,7 @@ async function exportHTML(): Promise<void> {
586582
allowProtocolRelative: false,
587583
})
588584
589-
const blob: Blob = new Blob([htmlContent], {type: 'text/html;charset=utf-8'})
585+
const blob: Blob = new Blob([htmlContent], { type: 'text/html;charset=utf-8' })
590586
saveAs(blob, suggestedName)
591587
}
592588

0 commit comments

Comments
 (0)