Skip to content

Commit 966af42

Browse files
feat(X-Pack): Supports third-party platforms as the default login method
1 parent c88a587 commit 966af42

File tree

7 files changed

+61
-46
lines changed

7 files changed

+61
-46
lines changed

backend/apps/system/api/parameter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
from sqlbot_xpack.config.model import SysArgModel
44

55

6-
from apps.system.crud.parameter_manage import get_parameter_args, save_parameter_args
6+
from apps.system.crud.parameter_manage import get_groups, get_parameter_args, save_parameter_args
77
from common.core.deps import SessionDep
88

99
router = APIRouter(tags=["system/parameter"], prefix="/system/parameter")
1010

11+
@router.get("/login")
12+
async def get_login_args(session: SessionDep) -> list[SysArgModel]:
13+
return await get_groups(session, "login")
14+
1115
@router.get("")
1216
async def get_args(session: SessionDep) -> list[SysArgModel]:
1317
return await get_parameter_args(session)

backend/apps/system/crud/parameter_manage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ async def get_parameter_args(session: SessionDep) -> list[SysArgModel]:
99
group_args = await get_group_args(session=session)
1010
return [x for x in group_args if not x.pkey.startswith('appearance.')]
1111

12+
async def get_groups(session: SessionDep, flag: str) -> list[SysArgModel]:
13+
group_args = await get_group_args(session=session, flag=flag)
14+
return group_args
15+
1216
async def save_parameter_args(session: SessionDep, request: Request):
1317
allow_file_mapping = {
1418
""" "test_logo": { "types": [".jpg", ".jpeg", ".png", ".svg"], "size": 5 * 1024 * 1024 } """

backend/common/utils/whitelist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"/system/authentication/platform/status",
3737
"/system/authentication/login/*",
3838
"/system/authentication/sso/*",
39+
"/system/parameter/login"
3940
]
4041

4142
class WhitelistChecker:

frontend/src/router/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ export const routes = [
231231
name: 'assistantTest',
232232
component: assistantTest,
233233
},
234+
{
235+
path: '/admin-login',
236+
name: 'admin-login',
237+
component: login,
238+
},
234239
{
235240
path: '/401',
236241
name: '401',

frontend/src/router/watch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { Router } from 'vue-router'
88
const appearanceStore = useAppearanceStoreWithOut()
99
const userStore = useUserStore()
1010
const { wsCache } = useCache()
11-
const whiteList = ['/login']
11+
const whiteList = ['/login', '/admin-login']
1212
const assistantWhiteList = ['/assistant', '/embeddedPage', '/401']
1313
export const watchRouter = (router: Router) => {
1414
router.beforeEach(async (to: any, from: any, next: any) => {
@@ -40,7 +40,7 @@ export const watchRouter = (router: Router) => {
4040
next('/chat')
4141
return
4242
}
43-
if (to.path === '/login') {
43+
if (to.path === '/login' || to.path === '/admin-login') {
4444
console.info(from)
4545
next('/chat')
4646
} else {

frontend/src/views/login/xpack/Handler.vue

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</template>
5252

5353
<script lang="ts" setup>
54-
import { ref, onMounted } from 'vue'
54+
import { ref, onMounted, nextTick, computed } from 'vue'
5555
import QrcodeLdap from './QrcodeLdap.vue'
5656
import LdapLoginForm from './LdapLoginForm.vue'
5757
/* import Oidc from './Oidc.vue'
@@ -77,14 +77,18 @@ defineProps<{
7777
loading: boolean
7878
}>()
7979
const emits = defineEmits(['switchTab', 'autoCallback', 'update:loading'])
80-
const updateLoading = (show: boolean) => {
81-
emits('update:loading', show)
80+
const updateLoading = (show: boolean, time: number = 1000) => {
81+
setTimeout(() => {
82+
emits('update:loading', show)
83+
}, time)
8284
}
8385
const { t } = useI18n()
8486
interface Categoryparam {
8587
category: string
8688
proxy?: string
8789
}
90+
91+
const adminLogin = computed(() => router.currentRoute?.value?.name === 'admin-login')
8892
const loginDialogVisible = ref(false)
8993
const dialogTitle = ref('')
9094
const dialogInterval = ref<any>(null)
@@ -102,7 +106,7 @@ const userStore = useUserStore()
102106
const qrStatus = ref(false)
103107
const loginCategory = ref({} as LoginCategory)
104108
const anyEnable = ref(false)
105-
// const qrcodeLdapHandler = ref()
109+
const qrcodeLdapHandler = ref()
106110
const oauth2Handler = ref()
107111
const saml2Handler = ref()
108112
/* const state = reactive({
@@ -232,21 +236,21 @@ const toMfa = (mfa) => {
232236
document.getElementsByClassName('preheat-container')[0].setAttribute('style', 'display: none;')
233237
}
234238
} */
235-
/* const ssoLogin = (category) => {
239+
const ssoLogin = (category: any) => {
236240
const array = [
237-
{ category: 'ldap', proxy: '' },
238-
{ category: 'oidc', proxy: '/oidcbi/#' },
239241
{ category: 'cas', proxy: '/casbi/#' },
242+
{ category: 'oidc', proxy: '/oidcbi/#' },
243+
{ category: 'ldap', proxy: '' },
240244
{ category: 'oauth2', proxy: '/#' },
241245
{ category: 'saml2', proxy: '/#' },
242246
]
243247
if (category) {
244-
if (category === 1) {
248+
if (category === 3) {
245249
qrcodeLdapHandler.value?.setActive('ldap')
246250
}
247251
switcherCategory(array[category - 1])
248252
}
249-
} */
253+
}
250254
251255
const switcherCategory = async (param: Categoryparam) => {
252256
const { category, proxy } = param
@@ -540,47 +544,41 @@ const callBackType = () => {
540544
return getQueryString('state')
541545
}
542546
543-
/* const auto2Platform = async () => {
544-
const resultParam = {
545-
preheat: true,
546-
loadingText: '加载中...',
547-
activeName: 'simple',
547+
const auto2Platform = async () => {
548+
if (adminLogin.value) {
549+
updateLoading(false, 100)
550+
return
548551
}
549-
if (!checkPlatform()) {
550-
const res = await loginCategoryApi()
551-
const adminLogin = router.currentRoute?.value?.name === 'admin-login'
552-
if (adminLogin && (!res.data || res.data === 1)) {
553-
emits('autoCallback', resultParam)
554-
router.push('/401')
555-
return
556-
}
557-
if (res.data && !adminLogin) {
558-
if (res.data === 1) {
559-
resultParam.activeName = 'ldap'
560-
resultParam.preheat = false
561-
} else {
562-
resultParam.loadingText = '加载中...'
563-
document.getElementsByClassName('ed-loading-text')?.length &&
564-
(document.getElementsByClassName('ed-loading-text')[0]['innerText'] =
565-
resultParam.loadingText)
566-
}
567-
nextTick(() => {
568-
ssoLogin(res.data)
569-
})
570-
} else {
571-
resultParam.preheat = false
552+
const resData = await request.get('/system/parameter/login')
553+
let res = 0
554+
const resObj = {} as any
555+
resData.forEach((item: any) => {
556+
resObj[item.pkey] = item.pval
557+
})
558+
res = parseInt(resObj['login.default_login'] || 0)
559+
560+
if (res && !adminLogin.value) {
561+
if (res === 3) {
562+
qrStatusChange('ldap')
563+
updateLoading(false)
572564
}
573-
} else if (getQueryString('state')?.includes('fit2clouddeoauth2')) {
574-
resultParam.preheat = true
565+
nextTick(() => {
566+
ssoLogin(res)
567+
})
568+
} else {
569+
updateLoading(false)
575570
}
576-
emits('autoCallback', resultParam)
577-
} */
571+
}
578572
579573
onMounted(() => {
574+
if (adminLogin.value) {
575+
updateLoading(false, 100)
576+
return
577+
}
580578
// eslint-disable-next-line no-undef
581579
const obj = LicenseGenerator.getLicense()
582580
if (obj?.status !== 'valid') {
583-
updateLoading(false)
581+
updateLoading(false, 100)
584582
return
585583
}
586584
wsCache.delete('de-platform-client')
@@ -594,7 +592,7 @@ onMounted(() => {
594592
} else if (state?.includes('oidc')) {
595593
oidcLogin()
596594
} else {
597-
updateLoading(false)
595+
auto2Platform()
598596
}
599597
/* else if (window.location.pathname.includes('/oidcbi/')) {
600598
platformLogin(2)

frontend/src/views/login/xpack/QrcodeLdap.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ const setActive = (active?: string) => {
139139
}
140140
validComponentList.value[index] = componentMap.value[activeComponent.value]
141141
activeComponent.value = item.key
142+
if (active === 'ldap') {
143+
hiddenDefaultTabs()
144+
}
142145
}
143146
defineExpose({
144147
setActive,

0 commit comments

Comments
 (0)