next/pages/auth/register.vue

119 lines
3.7 KiB
Vue
Raw Normal View History

2023-10-10 22:39:04 -04:00
<script lang="ts" setup>
2023-12-29 20:11:07 -05:00
import { Field as veeField, useField, useForm } from "vee-validate";
2023-10-10 22:39:04 -04:00
import * as yup from "yup";
import { useRecaptchaProvider } from "vue-recaptcha";
import { useChallengeV2 } from "vue-recaptcha";
import { notification } from "ant-design-vue";
import termsOfServices from "~/components/tos.vue";
import Recaptcha from "~/components/recaptcha.vue";
2023-10-10 22:39:04 -04:00
useRecaptchaProvider();
interface FormState {
username: string;
password: string;
email: string;
recaptcha?: string | null;
agree: boolean;
}
definePageMeta({
auth: {
unauthenticatedOnly: true,
navigateAuthenticatedTo: "/",
},
middleware: ["auth"],
2023-10-10 22:39:04 -04:00
});
// const { execute } = useChallengeV3('submit');
const vschema = yup.object<FormState>().shape({
2023-12-29 20:11:07 -05:00
username: yup.string().ensure().trim().min(1).required("Username is required!"),
password: yup.string().ensure().trim().min(8).required("Password is required!"),
2023-10-10 22:39:04 -04:00
email: yup.string().ensure().trim().email().required("Email is required!"),
// recaptcha: yup.string().required('Please verify you are human.'),
2023-12-29 20:11:07 -05:00
agree: yup.boolean().oneOf([true], "Please agree to the terms.").required("Please agree to the terms."),
2023-10-10 22:39:04 -04:00
});
const dv: FormState = {
username: "",
password: "",
email: "",
agree: false,
};
const dark = inject<boolean>("dark");
const { setValues, values, handleSubmit, setFieldValue } = useForm({
2023-10-10 22:39:04 -04:00
validationSchema: vschema,
keepValuesOnUnmount: true,
});
const onFinish = handleSubmit(async (values: any, actions: any) => {
// log.debug(values, widgetID);
// log.debug(widgetID);
const { signUp } = useAuth();
let reso;
try {
reso = await signUp(values, { callbackUrl: "/" });
} catch (e: any) {
// log.debug(e.data);
if (e.data) {
notification["error"]({
message: h("div", { innerHTML: e.data.message }),
});
}
}
});
const ts = ref(Date.now());
2023-10-10 22:39:04 -04:00
</script>
<template>
<form @submit="onFinish">
<vee-field name="username" v-slot="{ field, errorMessage, value }">
2023-12-29 20:11:07 -05:00
<a-form-item label="Username" :name="field.name" :validate-status="!!errorMessage ? 'error' : ''" :help="errorMessage">
2023-10-10 22:39:04 -04:00
<a-input v-bind="field" v-model:value="field.value" />
</a-form-item>
</vee-field>
<vee-field name="email" v-slot="{ field, errorMessage, value }">
2023-12-29 20:11:07 -05:00
<a-form-item label="Email address" :name="field.name" :validate-status="!!errorMessage ? 'error' : ''" :help="errorMessage">
2023-10-10 22:39:04 -04:00
<a-input v-bind="field" v-model:value="field.value" />
</a-form-item>
</vee-field>
<vee-field name="password" v-slot="{ field, errorMessage, value }">
2023-12-29 20:11:07 -05:00
<a-form-item label="Password" :name="field.name" :validate-status="!!errorMessage ? 'error' : ''" :help="errorMessage">
2023-10-10 22:39:04 -04:00
<a-input-password v-bind="field" v-model:value="field.value" />
</a-form-item>
</vee-field>
2023-12-29 20:11:07 -05:00
<a-typography-title :level="4" :style="{ textAlign: 'center' }">Terms</a-typography-title>
2023-10-10 22:39:04 -04:00
<div class="maxHeightScroller">
<div style="height: 100%">
<terms-of-services />
2023-12-29 20:11:07 -05:00
<vee-field name="agree" :unchecked-value="false" type="checkbox" v-slot="{ field, value, errorMessage }">
2023-10-10 22:39:04 -04:00
<a-checkbox
@update:checked="
(n) => {
setValues({ agree: n });
ts = Date.now();
2023-10-10 22:39:04 -04:00
}
"
>
I agree to the Terms and am <b>18 years of age or older.</b>
</a-checkbox>
<div style="color: red">{{ errorMessage }}</div>
</vee-field>
</div>
</div>
<recaptcha v-model:ts="ts" @verify="(res) => setFieldValue('recaptcha', res)" />
2023-10-10 22:39:04 -04:00
<a-row :align="'middle'" justify="center">
<a-col>
2023-12-29 20:11:07 -05:00
<a-button size="large" type="primary" html-type="submit">Sign me up!</a-button>
2023-10-10 22:39:04 -04:00
</a-col>
</a-row>
</form>
</template>
<style scoped>
.maxHeightScroller {
max-height: 400px;
overflow-y: scroll;
display: block;
}
</style>