work on user add

This commit is contained in:
jb-alvarado 2024-06-18 08:56:12 +02:00
parent 7900ad5e09
commit 9ec57055e6
6 changed files with 33 additions and 12 deletions

View File

@ -57,7 +57,7 @@
</div> </div>
<GenericModal :show="showUserModal" title="Add user" :modal-action="addUser"> <GenericModal :show="showUserModal" title="Add user" :modal-action="addUser">
<div class="w-full max-w-[500px] h-[420px]"> <div class="w-full max-w-[500px] h-[490px]">
<label class="form-control w-full"> <label class="form-control w-full">
<div class="label"> <div class="label">
<span class="label-text">{{ $t('user.name') }}</span> <span class="label-text">{{ $t('user.name') }}</span>
@ -86,6 +86,13 @@
<input v-model="user.confirm" type="password" class="input input-bordered w-full" /> <input v-model="user.confirm" type="password" class="input input-bordered w-full" />
</label> </label>
<div class="form-control mt-5">
<select v-model="user.channel_id" class="select select-bordered select-md w-full">
<option disabled selected>Channel</option>
<option v-for="channel in configStore.configChannel" :key="channel.id" :value="channel.id">{{ channel.name }}</option>
</select>
</div>
<div class="form-control mt-3"> <div class="form-control mt-3">
<label class="label cursor-pointer w-1/2"> <label class="label cursor-pointer w-1/2">
<span class="label-text">{{ $t('user.admin') }}</span> <span class="label-text">{{ $t('user.admin') }}</span>
@ -116,7 +123,8 @@ const user = ref({
password: '', password: '',
confirm: '', confirm: '',
admin: false, admin: false,
role_id: 2, channel_id: 1,
role_id: 3,
} as User) } as User)
onMounted(() => { onMounted(() => {
@ -187,20 +195,21 @@ function clearUser() {
user.value.password = '' user.value.password = ''
user.value.confirm = '' user.value.confirm = ''
user.value.admin = false user.value.admin = false
user.value.role_id = 2 user.value.channel_id = 1
user.value.role_id = 3
} }
async function addUser(add: boolean) { async function addUser(add: boolean) {
if (add) { if (add) {
if (user.value.admin) { if (user.value.admin) {
user.value.role_id = 1
} else {
user.value.role_id = 2 user.value.role_id = 2
} else {
user.value.role_id = 3
} }
delete user.value.admin delete user.value.admin
if (user.value.password === user.value.confirm) { if (user.value.username && user.value.password && user.value.password === user.value.confirm) {
authStore.inspectToken() authStore.inspectToken()
const update = await configStore.addNewUser(user.value) const update = await configStore.addNewUser(user.value)
showUserModal.value = false showUserModal.value = false

8
package-lock.json generated
View File

@ -33,7 +33,7 @@
"daisyui": "^4.12.2", "daisyui": "^4.12.2",
"postcss": "^8.4.38", "postcss": "^8.4.38",
"postcss-loader": "^8.1.1", "postcss-loader": "^8.1.1",
"sass": "^1.77.5", "sass": "^1.77.6",
"sass-loader": "^14.2.1", "sass-loader": "^14.2.1",
"vue": "^3.4.29", "vue": "^3.4.29",
"vue-router": "^4.3.3" "vue-router": "^4.3.3"
@ -14188,9 +14188,9 @@
"optional": true "optional": true
}, },
"node_modules/sass": { "node_modules/sass": {
"version": "1.77.5", "version": "1.77.6",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.77.5.tgz", "resolved": "https://registry.npmjs.org/sass/-/sass-1.77.6.tgz",
"integrity": "sha512-oDfX1mukIlxacPdQqNb6mV2tVCrnE+P3nVYioy72V5tlk56CPNcO4TCuFcaCRKKfJ1M3lH95CleRS+dVKL2qMg==", "integrity": "sha512-ByXE1oLD79GVq9Ht1PeHWCPMPB8XHpBuz1r85oByKHjZY6qV6rWnQovQzXJXuQ/XyE1Oj3iPk3lo28uzaRA2/Q==",
"devOptional": true, "devOptional": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View File

@ -37,7 +37,7 @@
"daisyui": "^4.12.2", "daisyui": "^4.12.2",
"postcss": "^8.4.38", "postcss": "^8.4.38",
"postcss-loader": "^8.1.1", "postcss-loader": "^8.1.1",
"sass": "^1.77.5", "sass": "^1.77.6",
"sass-loader": "^14.2.1", "sass-loader": "^14.2.1",
"vue": "^3.4.29", "vue": "^3.4.29",
"vue-router": "^4.3.3" "vue-router": "^4.3.3"

View File

@ -9,6 +9,7 @@
{{ $t('config.channel') }} {{ $t('config.channel') }}
</button> </button>
<button <button
v-if="authStore.role === 'GlobalAdmin'"
class="join-item w-full btn btn-sm btn-primary duration-500" class="join-item w-full btn btn-sm btn-primary duration-500"
:class="activeConf === 2 && 'btn-secondary'" :class="activeConf === 2 && 'btn-secondary'"
@click="activeConf = 2" @click="activeConf = 2"
@ -53,6 +54,8 @@
<script setup lang="ts"> <script setup lang="ts">
const { t } = useI18n() const { t } = useI18n()
const authStore = useAuth()
useHead({ useHead({
title: `${t('button.configure')} | ffplayout`, title: `${t('button.configure')} | ffplayout`,
}) })

View File

@ -6,6 +6,7 @@ export const useAuth = defineStore('auth', {
isLogin: false, isLogin: false,
jwtToken: '', jwtToken: '',
authHeader: {}, authHeader: {},
channelID: 0,
role: '', role: '',
uuid: null as null | string, uuid: null as null | string,
}), }),
@ -50,6 +51,7 @@ export const useAuth = defineStore('auth', {
this.updateToken(response.user?.token) this.updateToken(response.user?.token)
const decodedToken = jwtDecode<JwtPayloadExt>(response.user?.token) const decodedToken = jwtDecode<JwtPayloadExt>(response.user?.token)
this.isLogin = true this.isLogin = true
this.channelID = decodedToken.channel
this.role = decodedToken.role this.role = decodedToken.role
}) })
.catch(() => {}) .catch(() => {})
@ -65,7 +67,11 @@ export const useAuth = defineStore('auth', {
.then((response) => { .then((response) => {
this.uuid = response.uuid this.uuid = response.uuid
}) })
.catch(() => { .catch(e => {
console.log('status', e.status)
if (e.status === 401) {
this.removeToken()
}
this.uuid = null this.uuid = null
}) })
}, },
@ -78,6 +84,7 @@ export const useAuth = defineStore('auth', {
const decodedToken = jwtDecode<JwtPayloadExt>(token) const decodedToken = jwtDecode<JwtPayloadExt>(token)
const timestamp = Date.now() / 1000 const timestamp = Date.now() / 1000
const expireToken = decodedToken.exp const expireToken = decodedToken.exp
this.channelID = decodedToken.channel
this.role = decodedToken.role this.role = decodedToken.role
if (expireToken && this.jwtToken && expireToken - timestamp > 15) { if (expireToken && this.jwtToken && expireToken - timestamp > 15) {

2
types/index.d.ts vendored
View File

@ -4,6 +4,7 @@ export {}
declare global { declare global {
interface JwtPayloadExt extends JwtPayload { interface JwtPayloadExt extends JwtPayload {
channel: number
role: string role: string
} }
@ -36,6 +37,7 @@ declare global {
password?: string password?: string
confirm?: string confirm?: string
admin?: boolean admin?: boolean
channel_id?: number
role_id?: number role_id?: number
} }