-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
</script> | ||
|
||
<template> | ||
<login-modal /> | ||
<router-view /> | ||
</template> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<template> | ||
<el-dialog v-model="dialogVisible" :close-on-click-modal="false" width="600px"> | ||
Check failure on line 2 in kyuubi-server/web-ui/src/components/login/LoginModal.vue GitHub Actions / Style check (-Pflink-provided,hive-provided,spark-provided,spark-3.5,spark-3.4,spark-3.3,spark-3....
|
||
<div class="dialog-header"> | ||
<img class="logo" src="@/assets/images/kyuubi-logo.svg" /> | ||
</div> | ||
<el-form class="login-form"> | ||
<el-form-item label="Username"> | ||
<el-input v-model="username" placeholder="Username" /> | ||
</el-form-item> | ||
<el-form-item label="Password"> | ||
<el-input type="password" v-model="password" placeholder="Password" /> | ||
</el-form-item> | ||
<el-form-item> | ||
<p v-if="loginError" class="login-error">{{ loginError }}</p> | ||
</el-form-item> | ||
</el-form> | ||
<div slot="footer" class="dialog-footer"> | ||
<el-button @click="closeDialog">Cancel</el-button> | ||
<el-button type="primary" @click="handleLogin">Login</el-button> | ||
</div> | ||
</el-dialog> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref, onMounted } from 'vue'; | ||
Check failure on line 25 in kyuubi-server/web-ui/src/components/login/LoginModal.vue GitHub Actions / Style check (-Pflink-provided,hive-provided,spark-provided,spark-3.5,spark-3.4,spark-3.3,spark-3....
|
||
import { useAuthStore } from '@/pinia/auth/auth'; | ||
Check failure on line 26 in kyuubi-server/web-ui/src/components/login/LoginModal.vue GitHub Actions / Style check (-Pflink-provided,hive-provided,spark-provided,spark-3.5,spark-3.4,spark-3.3,spark-3....
|
||
const authStore = useAuthStore(); | ||
Check failure on line 28 in kyuubi-server/web-ui/src/components/login/LoginModal.vue GitHub Actions / Style check (-Pflink-provided,hive-provided,spark-provided,spark-3.5,spark-3.4,spark-3.3,spark-3....
|
||
const dialogVisible = ref(false); | ||
Check failure on line 29 in kyuubi-server/web-ui/src/components/login/LoginModal.vue GitHub Actions / Style check (-Pflink-provided,hive-provided,spark-provided,spark-3.5,spark-3.4,spark-3.3,spark-3....
|
||
const username = ref(''); | ||
Check failure on line 30 in kyuubi-server/web-ui/src/components/login/LoginModal.vue GitHub Actions / Style check (-Pflink-provided,hive-provided,spark-provided,spark-3.5,spark-3.4,spark-3.3,spark-3....
|
||
const password = ref(''); | ||
Check failure on line 31 in kyuubi-server/web-ui/src/components/login/LoginModal.vue GitHub Actions / Style check (-Pflink-provided,hive-provided,spark-provided,spark-3.5,spark-3.4,spark-3.3,spark-3....
|
||
const loginError = ref(''); | ||
Check failure on line 32 in kyuubi-server/web-ui/src/components/login/LoginModal.vue GitHub Actions / Style check (-Pflink-provided,hive-provided,spark-provided,spark-3.5,spark-3.4,spark-3.3,spark-3....
|
||
const handleLogin = async () => { | ||
try { | ||
await authStore.setUser(username.value, password.value); | ||
dialogVisible.value = false; | ||
loginError.value = ''; | ||
} catch (error) { | ||
loginError.value = (error as Error).message; | ||
} | ||
}; | ||
const closeDialog = () => { | ||
dialogVisible.value = false; | ||
loginError.value = ''; | ||
}; | ||
onMounted(() => { | ||
window.addEventListener('auth-required', () => { | ||
dialogVisible.value = true; | ||
}); | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
.dialog-header { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
margin-bottom: 20px; | ||
} | ||
.logo { | ||
width: 80px; | ||
height: auto; | ||
margin-bottom: 10px; | ||
} | ||
.login-form { | ||
margin-bottom: 20px; | ||
} | ||
.login-error { | ||
color: red; | ||
margin-top: 10px; | ||
text-align: center; | ||
} | ||
.dialog-footer { | ||
text-align: right; | ||
padding: 15px 20px; | ||
&>button:not(:last-child) { | ||
margin-right: 10px; | ||
} | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { defineStore } from 'pinia'; | ||
import request from '@/utils/request'; | ||
|
||
export const useAuthStore = defineStore('auth', { | ||
state: () => ({ | ||
user: null as string | null, | ||
authToken: null as string | null, | ||
isAuthenticated: false, | ||
}), | ||
actions: { | ||
async setUser(user: string, password: string) { | ||
try { | ||
const response = await request({ | ||
url: 'api/v1/ping', | ||
method: 'get', | ||
auth: { | ||
username: user, | ||
password: password, | ||
}, | ||
}); | ||
|
||
if (response) { | ||
this.user = user; | ||
this.authToken = `Basic ${btoa(user + ':' + password)}`; | ||
this.isAuthenticated = true; | ||
} else { | ||
throw new Error('Authentication failed'); | ||
} | ||
} catch (error) { | ||
throw error; | ||
} | ||
}, | ||
clearUser() { | ||
this.user = null; | ||
this.authToken = null; | ||
this.isAuthenticated = false; | ||
}, | ||
}, | ||
persist: { | ||
key: 'auth', | ||
}, | ||
}); |