ffplayout/pages/index.vue

145 lines
4.8 KiB
Vue
Raw Normal View History

2020-01-29 11:40:15 -05:00
<template>
<div>
2023-01-11 04:54:25 -05:00
<div v-if="authStore.isLogin">
<div class="container login-container">
<div>
2023-11-18 16:30:57 -05:00
<SystemStats v-if="configStore.configGui.length > 0" class="mx-auto" />
2023-11-16 09:45:46 -05:00
<div class="text-center mt-5">
2023-01-11 04:54:25 -05:00
<div class="btn-group actions-grp btn-group-lg" role="group">
<NuxtLink to="/player" class="btn btn-primary">Player</NuxtLink>
<NuxtLink to="/media" class="btn btn-primary">Media</NuxtLink>
<NuxtLink to="/message" class="btn btn-primary">Message</NuxtLink>
<NuxtLink to="logging" class="btn btn-primary">Logging</NuxtLink>
<NuxtLink v-if="authStore.role.toLowerCase() == 'admin'" to="/configure" class="btn btn-primary"> Configure </NuxtLink>
2023-01-11 04:54:25 -05:00
<button class="btn btn-primary" @click="logout()">Logout</button>
</div>
</div>
</div>
2023-01-11 04:54:25 -05:00
</div>
</div>
<div v-else>
<div class="logout-div" />
<div class="container login-container">
<div>
2023-11-16 09:45:46 -05:00
<div class="text-center mb-5">
2023-01-11 04:54:25 -05:00
<h1>ffplayout</h1>
</div>
<form class="login-form" @submit.prevent="login">
<div id="input-group-1" class="mb-3">
<label for="input-user" class="form-label">User:</label>
<input
type="text"
id="input-user"
class="form-control"
v-model="formUsername"
aria-describedby="Username"
required
/>
</div>
<div class="mb-3">
<label for="input-pass" class="form-label">Password:</label>
<input
type="password"
id="input-pass"
class="form-control"
v-model="formPassword"
required
/>
</div>
<div class="row">
<div class="col-3">
<button class="btn btn-primary" type="submit">Login</button>
</div>
<div class="col-9">
<div
class="alert alert-danger alert-dismissible fade login-alert"
:class="{ show: showError }"
role="alert"
>
{{ formError }}
<button
type="button"
class="btn-close"
data-bs-dismiss="alert"
aria-label="Close"
></button>
</div>
</div>
</div>
</form>
</div>
</div>
2020-01-29 11:40:15 -05:00
</div>
</div>
2020-01-29 11:40:15 -05:00
</template>
2023-01-11 04:54:25 -05:00
<script setup lang="ts">
const authStore = useAuth()
const configStore = useConfig()
const formError = ref('')
const showError = ref(false)
const formUsername = ref('')
const formPassword = ref('')
authStore.inspectToken()
async function login() {
try {
const status = await authStore.obtainToken(formUsername.value, formPassword.value)
formUsername.value = ''
formPassword.value = ''
formError.value = ''
if (status === 401 || status === 400 || status === 403) {
formError.value = 'Wrong User/Password!'
showError.value = true
2020-01-29 11:40:15 -05:00
}
2023-01-11 04:54:25 -05:00
await configStore.nuxtClientInit()
} catch (e) {
formError.value = e as string
}
}
async function logout() {
try {
authStore.removeToken()
} catch (e) {
formError.value = e as string
2020-01-29 11:40:15 -05:00
}
}
</script>
2023-01-11 04:54:25 -05:00
<style lang="scss">
2020-01-29 11:40:15 -05:00
.login-container {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.login-form {
min-width: 300px;
}
2023-01-11 04:54:25 -05:00
.login-alert {
padding: 0.4em;
--bs-alert-margin-bottom: 0;
2023-01-11 04:54:25 -05:00
.btn-close {
padding: 0.65rem 0.5rem;
}
}
@media (max-width: 380px) {
.actions-grp {
display: flex;
flex-direction: column;
margin: 0 2em 0 2em;
}
}
2020-01-29 11:40:15 -05:00
</style>