This is an automated email from the ASF dual-hosted git repository.

arshad pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/seatunnel-web.git


The following commit(s) were added to refs/heads/main by this push:
     new 9a208f74 [Improve] Enable Selecting Workspace and LDAP from UI (#287)
9a208f74 is described below

commit 9a208f74df1c9ea3cd4380ba991c43b28c23905f
Author: Shashwat Tiwari <shati...@visa.com>
AuthorDate: Sat Apr 12 17:34:11 2025 +0530

    [Improve] Enable Selecting Workspace and LDAP from UI (#287)
    
    Co-authored-by: Mohammad Arshad <ars...@apache.org>
---
 seatunnel-ui/src/locales/en_US/login.ts       |  5 ++++-
 seatunnel-ui/src/locales/en_US/user-manage.ts |  1 +
 seatunnel-ui/src/locales/zh_CN/login.ts       |  5 ++++-
 seatunnel-ui/src/locales/zh_CN/user-manage.ts |  1 +
 seatunnel-ui/src/service/user/index.ts        | 14 ++++++++++---
 seatunnel-ui/src/service/user/types.ts        |  7 ++++++-
 seatunnel-ui/src/store/setting/index.ts       | 11 ++++++++--
 seatunnel-ui/src/store/setting/types.ts       |  1 +
 seatunnel-ui/src/views/login/index.tsx        | 22 ++++++++++++++++++--
 seatunnel-ui/src/views/login/use-form.ts      | 29 +++++++++++++++++++++------
 10 files changed, 80 insertions(+), 16 deletions(-)

diff --git a/seatunnel-ui/src/locales/en_US/login.ts 
b/seatunnel-ui/src/locales/en_US/login.ts
index 1261d102..68f1b1a3 100644
--- a/seatunnel-ui/src/locales/en_US/login.ts
+++ b/seatunnel-ui/src/locales/en_US/login.ts
@@ -21,5 +21,8 @@ export default {
   username: 'Username',
   password: 'Password',
   username_tips: 'Please input username',
-  password_tips: 'Please input password'
+  password_tips: 'Please input password',
+  use_ldap: 'Ldap Authentication',
+  select_workspace: 'Select Workspace',
+  select_workspace_tips: 'Please select workspace'
 }
diff --git a/seatunnel-ui/src/locales/en_US/user-manage.ts 
b/seatunnel-ui/src/locales/en_US/user-manage.ts
index f689e8ed..de761bf3 100644
--- a/seatunnel-ui/src/locales/en_US/user-manage.ts
+++ b/seatunnel-ui/src/locales/en_US/user-manage.ts
@@ -34,6 +34,7 @@ export default {
   model_validate_tips: 'Required Fields',
   username_tips: 'Required fields, number, letter case, 50 characters',
   password_tips: 'Required fields, number, letter case, 6 characters',
+  use_ldap: 'Ldap Authentication',
   user_delete_tips:
     'Whether to delete the user? It cannot be restored after being deleted'
 }
diff --git a/seatunnel-ui/src/locales/zh_CN/login.ts 
b/seatunnel-ui/src/locales/zh_CN/login.ts
index db12f171..982c15d2 100644
--- a/seatunnel-ui/src/locales/zh_CN/login.ts
+++ b/seatunnel-ui/src/locales/zh_CN/login.ts
@@ -21,5 +21,8 @@ export default {
   username: '用户名',
   password: '密码',
   username_tips: '请输入用户名',
-  password_tips: '请输入密码'
+  password_tips: '请输入密码',
+  use_ldap: 'Ldap 认证',
+  select_workspace: '选择工作空间',
+  select_workspace_tips: '请选择工作空间'
 }
diff --git a/seatunnel-ui/src/locales/zh_CN/user-manage.ts 
b/seatunnel-ui/src/locales/zh_CN/user-manage.ts
index 46a60c6f..fcca7a2b 100644
--- a/seatunnel-ui/src/locales/zh_CN/user-manage.ts
+++ b/seatunnel-ui/src/locales/zh_CN/user-manage.ts
@@ -34,6 +34,7 @@ export default {
   model_validate_tips: '必填字段',
   username_tips: '必填字段,数字,字母大小写,50 个字符',
   password_tips: '必填字段,数字,字母大小写,6 个字符',
+  use_ldap: 'Ldap 认证',
   user_delete_tips:
     '是否删除用户? 删除后无法恢复'
 }
diff --git a/seatunnel-ui/src/service/user/index.ts 
b/seatunnel-ui/src/service/user/index.ts
index d6f9d47c..d8379eae 100644
--- a/seatunnel-ui/src/service/user/index.ts
+++ b/seatunnel-ui/src/service/user/index.ts
@@ -16,7 +16,7 @@
  */
 
 import { axios } from '@/service/service'
-import type { UserList, UserLogin, UserDetail } from '@/service/user/types'
+import type { UserList, UserLogin, SeatunnelHeader, UserDetail } from 
'@/service/user/types'
 
 export function userList(params: UserList): any {
   return axios({
@@ -34,11 +34,19 @@ export function userAdd(data: UserDetail): any {
   })
 }
 
-export function userLogin(data: UserLogin): any {
+export function userLogin(data: UserLogin, config: SeatunnelHeader): any {
   return axios({
     url: '/user/login',
     method: 'post',
-    data
+    data,
+    headers: config.headers
+  })
+}
+
+export function fetchWorkspaces(): any {
+  return axios({
+    url: '/resources/workspace',
+    method: 'get'
   })
 }
 
diff --git a/seatunnel-ui/src/service/user/types.ts 
b/seatunnel-ui/src/service/user/types.ts
index 31ef9e56..f3ca6e25 100644
--- a/seatunnel-ui/src/service/user/types.ts
+++ b/seatunnel-ui/src/service/user/types.ts
@@ -24,6 +24,11 @@ interface UserList {
 interface UserLogin {
   password: string
   username: string
+  workspace?: string
+}
+
+interface SeatunnelHeader {
+  headers: any | {}
 }
 
 interface UserDetail extends UserLogin {
@@ -36,4 +41,4 @@ interface UserDetail extends UserLogin {
   updateTime?: any | null
 }
 
-export { UserList, UserLogin, UserDetail }
+export { UserList, UserLogin, UserDetail, SeatunnelHeader }
diff --git a/seatunnel-ui/src/store/setting/index.ts 
b/seatunnel-ui/src/store/setting/index.ts
index b22e9f8d..ee70fabc 100644
--- a/seatunnel-ui/src/store/setting/index.ts
+++ b/seatunnel-ui/src/store/setting/index.ts
@@ -25,7 +25,8 @@ export const useSettingStore = defineStore({
     dataUniqueValue: false,
     fillet: 15,
     requestTime: 6000,
-    locales: 'en_US'
+    locales: 'en_US',
+    workspaces: []
   }),
   persist: true,
   getters: {
@@ -43,6 +44,9 @@ export const useSettingStore = defineStore({
     },
     getLocales(): Locales {
       return this.locales
+    },
+    getWorkspaces(): string[] {
+      return this.workspaces
     }
   },
   actions: {
@@ -60,6 +64,9 @@ export const useSettingStore = defineStore({
     },
     setLocales(lang: Locales): void {
       this.locales = lang
+    },
+    setWorkspaces(workspaces: string[]): void {
+      this.workspaces = workspaces
     }
   }
-})
+})
\ No newline at end of file
diff --git a/seatunnel-ui/src/store/setting/types.ts 
b/seatunnel-ui/src/store/setting/types.ts
index 3652c715..27e47284 100644
--- a/seatunnel-ui/src/store/setting/types.ts
+++ b/seatunnel-ui/src/store/setting/types.ts
@@ -23,6 +23,7 @@ interface SettingStore {
   fillet: number
   requestTime: number
   locales: Locales
+  workspaces: string[]
 }
 
 export { SettingStore, Locales }
diff --git a/seatunnel-ui/src/views/login/index.tsx 
b/seatunnel-ui/src/views/login/index.tsx
index 59e0b80b..fa8149a4 100644
--- a/seatunnel-ui/src/views/login/index.tsx
+++ b/seatunnel-ui/src/views/login/index.tsx
@@ -24,6 +24,8 @@ import {
   NFormItem,
   NInput,
   NButton,
+  NCheckbox,
+  NSelect,
   useMessage
 } from 'naive-ui'
 import { useI18n } from 'vue-i18n'
@@ -86,10 +88,26 @@ const Login = defineComponent({
                     onKeydown={withKeys(this.handleLogin, ['enter'])}
                   />
                 </NFormItem>
+                <NFormItem
+                    label={this.t('login.select_workspace')}
+                    label-style={{ color: 'black' }}
+                    path='selectedWorkspace'
+                >
+                  <NSelect
+                      options={this.workspaces.map(workspace => ({ label: 
workspace, value: workspace }))}
+                      v-model={[this.loginForm.selectedWorkspace, 'value']}
+                      placeholder={this.t('login.select_workspace_tips')}
+                  />
+                </NFormItem>
+                <NFormItem>
+                  <NCheckbox v-model={this.loginForm.useLdap} 
onUpdateChecked={(value) => this.loginForm.useLdap = value} >
+                    {this.t('login.use_ldap')}
+                  </NCheckbox>
+                </NFormItem>
               </NForm>
               <NButton
                 type='info'
-                disabled={!this.loginForm.username || !this.loginForm.password}
+                disabled={!this.loginForm.username || !this.loginForm.password 
|| !this.loginForm.selectedWorkspace}
                 style={{ width: '100%' }}
                 onClick={this.handleLogin}
               >
@@ -103,4 +121,4 @@ const Login = defineComponent({
   }
 })
 
-export default Login
+export default Login
\ No newline at end of file
diff --git a/seatunnel-ui/src/views/login/use-form.ts 
b/seatunnel-ui/src/views/login/use-form.ts
index c9fee48d..48129434 100644
--- a/seatunnel-ui/src/views/login/use-form.ts
+++ b/seatunnel-ui/src/views/login/use-form.ts
@@ -15,25 +15,30 @@
  * limitations under the License.
  */
 
-import { reactive, ref } from 'vue'
+import { reactive, ref, onMounted } from 'vue'
 import { useI18n } from 'vue-i18n'
-import { userLogin } from '@/service/user'
+import { fetchWorkspaces, userLogin } from '@/service/user'
 import { useUserStore } from '@/store/user'
 import { useRouter } from 'vue-router'
 import type { FormRules } from 'naive-ui'
 import type { Router } from 'vue-router'
+import { useSettingStore } from '@/store/setting'
 
 export function useForm() {
   const router: Router = useRouter()
   const { t } = useI18n()
   const userStore = useUserStore()
+  const settingStore = useSettingStore()
 
   const state = reactive({
     loginFormRef: ref(),
     loginForm: {
       username: '',
-      password: ''
+      password: '',
+      useLdap: false,
+      selectedWorkspace: ''
     },
+    workspaces: [] as string[],
     rules: {
       username: {
         trigger: ['input', 'blur'],
@@ -54,11 +59,23 @@ export function useForm() {
     } as FormRules
   })
 
+  onMounted(() => {
+    fetchWorkspaces().then((workspaces: string[]) => {
+      state.workspaces = workspaces
+      settingStore.setWorkspaces(workspaces)
+    }).catch((error: any) => {
+      console.error('Failed to fetch workspaces:', error)
+    })
+  })
+
   const handleLogin = () => {
-    userLogin({ ...state.loginForm }).then((res: any) => {
+    let { username, password, useLdap, selectedWorkspace } = state.loginForm
+    const headers = useLdap ? { 'X-Seatunnel-Auth-Type': 'LDAP' } : {}
+    userLogin({ username, password, workspace: selectedWorkspace }, { headers 
}).then((res: any) => {
       userStore.setUserInfo(res)
-      console.log('login-jumps')
       router.push({ path: '/tasks' })
+    }).catch((error: any) => {
+      console.error('Login failed:', error)
     })
   }
 
@@ -66,4 +83,4 @@ export function useForm() {
     state,
     handleLogin
   }
-}
+}
\ No newline at end of file

Reply via email to