Skip to content

Commit 4e170c6

Browse files
authored
feat: chat password auth (#3318)
1 parent 7aa73e7 commit 4e170c6

File tree

7 files changed

+100
-44
lines changed

7 files changed

+100
-44
lines changed

apps/common/auth/handle/impl/chat_anonymous_user_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def handle(self, request, token: str, get_token_details):
4545
if application_setting_model is not None:
4646
application_setting = QuerySet(application_setting_model).filter(application_id=application_id).first()
4747
if application_setting.authentication:
48-
if 'password' != chat_user_token.authentication.auth_type:
48+
if 'password' != application_setting.authentication_value.get('type', ''):
4949
raise AppAuthenticationFailed(1002, _('Authentication information is incorrect'))
5050
return None, ChatAuth(
5151
current_role_list=[RoleConstants.CHAT_ANONYMOUS_USER],

ui/src/api/chat/chat.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ const anonymousAuthentication: (
5959
) => Promise<Result<any>> = (assessToken, loading) => {
6060
return post('/auth/anonymous', { access_token: assessToken }, {}, loading)
6161
}
62+
/**
63+
* 密码认证
64+
* @param assessToken
65+
* @param password
66+
* @param loading
67+
* @returns
68+
*/
69+
const passwordAuthentication: (
70+
assessToken: string,
71+
password: string,
72+
loading?: Ref<boolean>,
73+
) => Promise<Result<any>> = (assessToken, password, loading) => {
74+
return post('auth/password', { access_token: assessToken, password: password }, {}, loading)
75+
}
6276
/**
6377
* 获取应用相关信息
6478
* @param loading
@@ -161,4 +175,5 @@ export default {
161175
getQrSource,
162176
ldapLogin,
163177
getAuthSetting,
178+
passwordAuthentication,
164179
}

ui/src/stores/modules/chat-user.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ const useChatUserStore = defineStore('chat-user', {
7474
return this.token
7575
})
7676
},
77+
passwordAuthentication(password: string) {
78+
return ChatAPI.passwordAuthentication(this.accessToken as string, password).then((ok) => {
79+
this.setToken(ok.data)
80+
return this.token
81+
})
82+
},
7783
login(request: LoginRequest, loading?: Ref<boolean>) {
7884
return ChatAPI.login(this.accessToken as string, request, loading).then((ok) => {
7985
this.setToken(ok.data.token)

ui/src/views/application-overview/xpack-component/XPackLimitDrawer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
class="mb-16"
4141
:class="form.authentication_value.type === 'password' ? 'active' : ''"
4242
>
43-
<el-radio value="replace" size="large">
43+
<el-radio value="password" size="large">
4444
<p class="mb-4 lighter">
4545
{{ $t('views.applicationOverview.appInfo.LimitDialog.authenticationValue') }}
4646
</p>

ui/src/views/chat/auth/component/password.vue

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,31 @@
11
<template>
2-
<el-dialog
3-
:modelValue="show"
4-
modal-class="positioned-mask"
5-
width="300"
6-
:title="$t('chat.passwordValidator.title')"
7-
custom-class="no-close-button"
8-
:close-on-click-modal="false"
9-
:close-on-press-escape="false"
10-
:show-close="false"
11-
top="25vh"
12-
center
13-
:modal="true"
14-
>
15-
<el-form ref="FormRef" :model="form" @submit.prevent="validator">
16-
<el-form-item prop="value" :rules="rules.value">
17-
<el-input show-password v-model="form.value" />
18-
</el-form-item>
19-
<el-button class="w-full mt-8" type="primary" @click="validator" :loading="loading">
20-
{{ $t('common.confirm') }}</el-button
21-
>
22-
</el-form>
23-
</el-dialog>
2+
<el-form ref="FormRef" :model="form" @submit.prevent="validator">
3+
<el-form-item prop="value" :rules="rules.password">
4+
<el-input show-password v-model="form.password" />
5+
</el-form-item>
6+
<el-button class="w-full mt-8" type="primary" @click="validator" :loading="loading">
7+
{{ $t('common.confirm') }}</el-button
8+
>
9+
</el-form>
2410
</template>
2511
<script setup lang="ts">
2612
import { ref, computed } from 'vue'
27-
import { useRoute } from 'vue-router'
13+
2814
import useStore from '@/stores'
2915
import { t } from '@/locales'
16+
import { useRoute, useRouter } from 'vue-router'
3017
const route = useRoute()
3118
const FormRef = ref()
32-
const {
33-
params: { accessToken }
34-
} = route as any
35-
const { application } = useStore()
19+
20+
const { chatUser } = useStore()
3621
const props = defineProps<{ applicationProfile: any; modelValue: boolean }>()
3722
const loading = ref<boolean>(false)
38-
const show = computed(() => {
39-
if (props.applicationProfile) {
40-
if (props.modelValue) {
41-
return false
42-
}
43-
return props.applicationProfile.authentication
44-
}
45-
return false
46-
})
23+
const router = useRouter()
24+
4725
const emit = defineEmits(['update:modelValue'])
4826
const auth = () => {
49-
return application.asyncAppAuthentication(accessToken, loading, form.value).then(() => {
50-
emit('update:modelValue', true)
27+
return chatUser.passwordAuthentication(form.value.password).then((ok) => {
28+
router.push({ name: 'chat', params: { accessToken: chatUser.accessToken } })
5129
})
5230
}
5331
const validator_auth = (rule: any, value: string, callback: any) => {
@@ -64,12 +42,11 @@ const validator = () => {
6442
}
6543
6644
const rules = {
67-
value: [{ required: true, validator: validator_auth, trigger: 'manual' }]
45+
password: [{ required: true, validator: validator_auth, trigger: 'manual' }],
6846
}
6947
7048
const form = ref({
71-
type: 'password',
72-
value: ''
49+
password: '',
7350
})
7451
</script>
7552
<style lang="scss">
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template>
2+
<div>
3+
<el-form ref="FormRef" :model="form" @submit.prevent="validator">
4+
<el-form-item prop="value" :rules="rules.value">
5+
<el-input show-password v-model="form.value" />
6+
</el-form-item>
7+
<el-button class="w-full mt-8" type="primary" @click="validator" :loading="loading">
8+
{{ $t('common.confirm') }}</el-button
9+
>
10+
</el-form>
11+
</div>
12+
</template>
13+
<script setup lang="ts">
14+
import { ref, computed } from 'vue'
15+
import { useRoute } from 'vue-router'
16+
import useStore from '@/stores'
17+
import { t } from '@/locales'
18+
const route = useRoute()
19+
const FormRef = ref()
20+
const {
21+
params: { accessToken },
22+
} = route as any
23+
const { application } = useStore()
24+
const loading = ref<boolean>(false)
25+
const auth = () => {
26+
return application.asyncAppAuthentication(accessToken, loading, form.value).then(() => {})
27+
}
28+
const validator_auth = (rule: any, value: string, callback: any) => {
29+
if (value === '') {
30+
callback(new Error(t('chat.passwordValidator.errorMessage1')))
31+
} else {
32+
auth().catch(() => {
33+
callback(new Error(t('chat.passwordValidator.errorMessage2')))
34+
})
35+
}
36+
}
37+
const validator = () => {
38+
FormRef.value.validate()
39+
}
40+
41+
const rules = {
42+
value: [{ required: true, validator: validator_auth, trigger: 'manual' }],
43+
}
44+
45+
const form = ref({
46+
type: 'password',
47+
value: '',
48+
})
49+
</script>
50+
<style lang="scss" scoped></style>

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<template>
22
<UserLoginLayout v-if="!loading" v-loading="loading">
3-
<LoginContainer :subTitle="theme.themeInfo?.slogan || $t('theme.defaultSlogan')">
3+
<LoginContainer
4+
v-if="chatUser.chat_profile?.authentication_type == 'password'"
5+
:subTitle="theme.themeInfo?.slogan || $t('theme.defaultSlogan')"
6+
>
7+
<PasswordAuth></PasswordAuth>
8+
</LoginContainer>
9+
10+
<LoginContainer v-else :subTitle="theme.themeInfo?.slogan || $t('theme.defaultSlogan')">
411
<h2 class="mb-24" v-if="!showQrCodeTab">
512
{{ loginMode == 'LOCAL' ? $t('views.login.title') : loginMode }}
613
</h2>
@@ -139,6 +146,7 @@ import useStore from '@/stores'
139146
import { useI18n } from 'vue-i18n'
140147
import QrCodeTab from '@/views/login/scanCompinents/QrCodeTab.vue'
141148
import { MsgConfirm, MsgError } from '@/utils/message.ts'
149+
import PasswordAuth from '@/views/chat/auth/component/password.vue'
142150
import useUserStore from '@/stores/modules/user.ts'
143151
144152
const router = useRouter()

0 commit comments

Comments
 (0)