From 4e170c6ed73b7551865d33c030e50e100e52226a Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Thu, 19 Jun 2025 20:02:52 +0800 Subject: [PATCH] feat: chat password auth (#3318) --- .../handle/impl/chat_anonymous_user_token.py | 2 +- ui/src/api/chat/chat.ts | 15 +++++ ui/src/stores/modules/chat-user.ts | 6 ++ .../xpack-component/XPackLimitDrawer.vue | 2 +- ui/src/views/chat/auth/component/password.vue | 59 ++++++------------- .../chat/user-login/auth/password/index.vue | 50 ++++++++++++++++ ui/src/views/chat/user-login/index.vue | 10 +++- 7 files changed, 100 insertions(+), 44 deletions(-) create mode 100644 ui/src/views/chat/user-login/auth/password/index.vue diff --git a/apps/common/auth/handle/impl/chat_anonymous_user_token.py b/apps/common/auth/handle/impl/chat_anonymous_user_token.py index 2296495a0..f048f99bc 100644 --- a/apps/common/auth/handle/impl/chat_anonymous_user_token.py +++ b/apps/common/auth/handle/impl/chat_anonymous_user_token.py @@ -45,7 +45,7 @@ class ChatAnonymousUserToken(AuthBaseHandle): if application_setting_model is not None: application_setting = QuerySet(application_setting_model).filter(application_id=application_id).first() if application_setting.authentication: - if 'password' != chat_user_token.authentication.auth_type: + if 'password' != application_setting.authentication_value.get('type', ''): raise AppAuthenticationFailed(1002, _('Authentication information is incorrect')) return None, ChatAuth( current_role_list=[RoleConstants.CHAT_ANONYMOUS_USER], diff --git a/ui/src/api/chat/chat.ts b/ui/src/api/chat/chat.ts index de7d4bbb8..a7d4bf77f 100644 --- a/ui/src/api/chat/chat.ts +++ b/ui/src/api/chat/chat.ts @@ -59,6 +59,20 @@ const anonymousAuthentication: ( ) => Promise> = (assessToken, loading) => { return post('/auth/anonymous', { access_token: assessToken }, {}, loading) } +/** + * 密码认证 + * @param assessToken + * @param password + * @param loading + * @returns + */ +const passwordAuthentication: ( + assessToken: string, + password: string, + loading?: Ref, +) => Promise> = (assessToken, password, loading) => { + return post('auth/password', { access_token: assessToken, password: password }, {}, loading) +} /** * 获取应用相关信息 * @param loading @@ -161,4 +175,5 @@ export default { getQrSource, ldapLogin, getAuthSetting, + passwordAuthentication, } diff --git a/ui/src/stores/modules/chat-user.ts b/ui/src/stores/modules/chat-user.ts index 3fd28b561..ea82cf760 100644 --- a/ui/src/stores/modules/chat-user.ts +++ b/ui/src/stores/modules/chat-user.ts @@ -74,6 +74,12 @@ const useChatUserStore = defineStore('chat-user', { return this.token }) }, + passwordAuthentication(password: string) { + return ChatAPI.passwordAuthentication(this.accessToken as string, password).then((ok) => { + this.setToken(ok.data) + return this.token + }) + }, login(request: LoginRequest, loading?: Ref) { return ChatAPI.login(this.accessToken as string, request, loading).then((ok) => { this.setToken(ok.data.token) diff --git a/ui/src/views/application-overview/xpack-component/XPackLimitDrawer.vue b/ui/src/views/application-overview/xpack-component/XPackLimitDrawer.vue index fa44ecbe7..a7fe967b9 100644 --- a/ui/src/views/application-overview/xpack-component/XPackLimitDrawer.vue +++ b/ui/src/views/application-overview/xpack-component/XPackLimitDrawer.vue @@ -40,7 +40,7 @@ class="mb-16" :class="form.authentication_value.type === 'password' ? 'active' : ''" > - +

{{ $t('views.applicationOverview.appInfo.LimitDialog.authenticationValue') }}

diff --git a/ui/src/views/chat/auth/component/password.vue b/ui/src/views/chat/auth/component/password.vue index 05b79fd84..b7a4db25d 100644 --- a/ui/src/views/chat/auth/component/password.vue +++ b/ui/src/views/chat/auth/component/password.vue @@ -1,53 +1,31 @@ diff --git a/ui/src/views/chat/user-login/index.vue b/ui/src/views/chat/user-login/index.vue index 7920faab8..da17f246c 100644 --- a/ui/src/views/chat/user-login/index.vue +++ b/ui/src/views/chat/user-login/index.vue @@ -1,6 +1,13 @@