|
| 1 | +<script setup lang="ts"> |
| 2 | +import { reactive } from "vue"; |
| 3 | +// import { invoke } from "@tauri-apps/api/core"; |
| 4 | +import { useToast } from 'primevue/usetoast'; |
| 5 | +import { useRouter } from "vue-router"; |
| 6 | +
|
| 7 | +const toast = useToast(); |
| 8 | +const router = useRouter(); |
| 9 | +
|
| 10 | +const initialValues = reactive({ |
| 11 | + identity: '', |
| 12 | + password: '', |
| 13 | + terms: false, |
| 14 | +}); |
| 15 | +
|
| 16 | +interface LoginForm { |
| 17 | + identity: string; |
| 18 | + password: string; |
| 19 | + terms: boolean; |
| 20 | +} |
| 21 | +
|
| 22 | +interface LoginErrors { |
| 23 | + identity?: { message: string }[]; |
| 24 | + password?: { message: string }[]; |
| 25 | + terms?: { message: string }[]; |
| 26 | +} |
| 27 | +
|
| 28 | +const resolver = ({ values }: { values: LoginForm }) => { |
| 29 | + const errors: LoginErrors = {}; |
| 30 | +
|
| 31 | + if (!values.identity) { |
| 32 | + errors.identity = [{ message: 'Please enter your username or email.' }]; |
| 33 | + } |
| 34 | +
|
| 35 | + if (!values.password) { |
| 36 | + errors.password = [{ message: 'Missing password.' }]; |
| 37 | + } |
| 38 | +
|
| 39 | + if (!values.terms) { |
| 40 | + errors.terms = [{ message: 'You must agree to the terms and conditions.' }]; |
| 41 | + } |
| 42 | +
|
| 43 | + return { errors }; |
| 44 | +}; |
| 45 | +
|
| 46 | +const onLogin = async ({ valid }: { valid: boolean }) => { |
| 47 | + if (valid) { |
| 48 | + toast.add({ severity: 'info', summary: 'Login unsupported', detail: 'Please wait while nightly versions are being updated.' }); |
| 49 | + } |
| 50 | +} |
| 51 | +</script> |
| 52 | + |
| 53 | +<template> |
| 54 | + <main class="w-full h-screen"> |
| 55 | + <div class="flex flex-col md:flex-row h-full w-full"> |
| 56 | + <div class="flex items-center justify-center h-full w-full"> |
| 57 | + <h1 class="text-4xl font-bold">ACM Algorithm Hub</h1> |
| 58 | + </div> |
| 59 | + <Card class="m-10 px-6 py-12 w-full"> |
| 60 | + <template #title>Welcome to ACM Algorithm Hub</template> |
| 61 | + <template #subtitle>Association of Computing Machinery affiliated with SWPU</template> |
| 62 | + <template #content class="h-full"> |
| 63 | + <Form v-slot="$form" :initialValues :resolver @submit="onLogin" |
| 64 | + class="flex flex-col p-6 gap-4 h-full items-center justify-center"> |
| 65 | + <div class="flex flex-col gap-1 w-full"> |
| 66 | + <InputText name="identity" type="text" placeholder="Username or Email" fluid /> |
| 67 | + <Message v-if="$form.identity?.invalid" severity="error" size="small" variant="simple">{{ |
| 68 | + $form.identity.error.message }}</Message> |
| 69 | + </div> |
| 70 | + <div class="flex flex-col gap-1 w-full"> |
| 71 | + <Password name="password" type="text" placeholder="Password" :feedback="false" toggleMask fluid /> |
| 72 | + <Message v-if="$form.password?.invalid" severity="error" size="small" variant="simple">{{ |
| 73 | + $form.password.error.message }}</Message> |
| 74 | + </div> |
| 75 | + <div class="flex flex-col gap-1 w-full"> |
| 76 | + <div class="flex items-center gap-2"> |
| 77 | + <Checkbox inputId="terms" name="terms" binary /> |
| 78 | + <label for="terms" class="text-sm">I have read and agree to the <a href="#" class="underline">Affero |
| 79 | + General Public License v3</a>.</label> |
| 80 | + </div> |
| 81 | + <Message v-if="$form.terms?.invalid" severity="error" size="small" variant="simple">{{ |
| 82 | + $form.terms.error.message }}</Message> |
| 83 | + </div> |
| 84 | + <p>Do not have an account? <a @click="router.push('/signup')" class="underline">Sign up</a></p> |
| 85 | + <Button type="submit" label="Login" class="w-full" secondary></Button> |
| 86 | + </Form> |
| 87 | + </template> |
| 88 | + <template #footer> |
| 89 | + </template> |
| 90 | + </Card> |
| 91 | + </div> |
| 92 | + </main> |
| 93 | +</template> |
0 commit comments