2024-11-24 20:50:39 -05:00
|
|
|
<script setup lang="ts">
|
2024-11-26 16:06:53 -05:00
|
|
|
import { computed, reactive, ref } from 'vue';
|
|
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
2024-11-24 20:50:39 -05:00
|
|
|
|
|
|
|
|
import Button from 'primevue/button';
|
|
|
|
|
import { Form } from '@primevue/forms';
|
|
|
|
|
import InputText from 'primevue/inputtext';
|
|
|
|
|
import Message from 'primevue/message';
|
|
|
|
|
import Toast from 'primevue/toast';
|
|
|
|
|
|
2024-12-01 20:54:21 -05:00
|
|
|
import { useSessionStore } from "@/stores/sessionStore";
|
2024-11-24 20:50:39 -05:00
|
|
|
|
2024-12-01 20:54:21 -05:00
|
|
|
|
|
|
|
|
const sessionStore = useSessionStore();
|
2024-11-24 20:50:39 -05:00
|
|
|
const username = ref();
|
|
|
|
|
const password = ref();
|
|
|
|
|
const router = useRouter();
|
2024-11-26 16:06:53 -05:00
|
|
|
const route = useRoute();
|
|
|
|
|
const next = route.query.next;
|
|
|
|
|
|
|
|
|
|
|
2024-11-24 20:50:39 -05:00
|
|
|
function handleLogin({ valid }) {
|
|
|
|
|
if (!valid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-01 20:54:21 -05:00
|
|
|
sessionStore.login(username.value, username.value).then(() => {
|
2024-11-26 16:06:53 -05:00
|
|
|
router.push(next);
|
2024-11-24 20:50:39 -05:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const initialValues = reactive({
|
|
|
|
|
username: 'joe',
|
|
|
|
|
password: 'password',
|
|
|
|
|
});
|
|
|
|
|
const resolver = ({ values }) => {
|
|
|
|
|
const errors = {};
|
|
|
|
|
if (!values.username) {
|
|
|
|
|
errors.username = [{message: 'Username is required.'}];
|
|
|
|
|
}
|
2024-11-26 21:34:57 -05:00
|
|
|
username.value = values.username;
|
2024-11-24 20:50:39 -05:00
|
|
|
if (!values.password) {
|
|
|
|
|
errors.password = [{message: 'Password is required.'}];
|
|
|
|
|
}
|
2024-11-26 21:34:57 -05:00
|
|
|
password.value = values.password;
|
2024-11-24 20:50:39 -05:00
|
|
|
return { errors }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="login-form">
|
|
|
|
|
<Toast/>
|
|
|
|
|
<Form :initialValues :resolver @submit="handleLogin" v-slot="$form">
|
|
|
|
|
<div>
|
|
|
|
|
<label for="username">Username</label>
|
|
|
|
|
<InputText name="username" v-model="username" id="username" type="text" />
|
|
|
|
|
<Message v-if="$form.username?.invalid" severity="error" size="small" variant="simple">
|
|
|
|
|
{{ $form.username.error?.message }}
|
|
|
|
|
</Message>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label for="password">Password</label>
|
|
|
|
|
<InputText name="password" v-model="password" id="password" type="password" />
|
|
|
|
|
<Message v-if="$form.password?.invalid" severity="error" size="small" variant="simple">
|
|
|
|
|
{{ $form.password.error?.message }}
|
|
|
|
|
</Message>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label> </label>
|
|
|
|
|
<Button type="submit">Login</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.login-form {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
form {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
font-size: 120%;
|
|
|
|
|
margin: 20px;
|
|
|
|
|
gap: 10px;
|
|
|
|
|
> div {
|
|
|
|
|
padding: 4px;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|