2024-04-15 03:16:57 +02:00
|
|
|
<template>
|
2024-06-15 23:18:58 +02:00
|
|
|
<div class="flex min-h-screen flex-col justify-center px-6 py-12 gap-10 lg:px-8 relative">
|
2024-06-16 08:35:20 +02:00
|
|
|
<img crossorigin="anonymous" src="https://cdn.lysand.org/logo.webp" alt="Lysand logo"
|
|
|
|
|
class="mx-auto hidden md:inline-block h-20" />
|
2024-06-16 02:04:17 +02:00
|
|
|
<div v-if="true" class="mx-auto w-full max-w-md">
|
2024-06-15 23:18:58 +02:00
|
|
|
<div v-if="Object.keys(errors).length > 0"
|
|
|
|
|
class="ring-1 ring-white/10 rounded p-4 bg-red-500 text-white mb-10">
|
|
|
|
|
<h2 class="font-bold text-lg">Error</h2>
|
|
|
|
|
<span class="text-sm">{{ errors.error }}</span>
|
|
|
|
|
</div>
|
2024-06-16 08:35:20 +02:00
|
|
|
<VeeForm class="flex flex-col gap-y-6" @submit="s => register((s as any))" :validation-schema="schema">
|
|
|
|
|
<h1 class="font-bold text-2xl text-gray-50 text-center tracking-tight">Account details</h1>
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2024-06-16 08:35:20 +02:00
|
|
|
<VeeField name="username" v-slot="{ errorMessage, field }" validate-on-change>
|
2024-06-21 04:09:09 +02:00
|
|
|
<Field>
|
|
|
|
|
<LabelAndError>
|
|
|
|
|
<Label for="username">Username</Label>
|
|
|
|
|
<FieldError v-if="errorMessage">{{ errorMessage }}</FieldError>
|
|
|
|
|
</LabelAndError>
|
|
|
|
|
<TextInput id="username" type="text" placeholder="thespeedy" required v-bind="field"
|
2024-06-16 08:35:20 +02:00
|
|
|
:disabled="isLoading" :is-invalid="!!errorMessage" autocomplete="username"
|
|
|
|
|
:spellcheck="false" />
|
2024-06-21 04:09:09 +02:00
|
|
|
</Field>
|
2024-06-15 23:18:58 +02:00
|
|
|
</VeeField>
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2024-06-16 08:35:20 +02:00
|
|
|
<VeeField name="email" v-slot="{ errorMessage, field }" validate-on-change>
|
2024-06-21 04:09:09 +02:00
|
|
|
<Field>
|
|
|
|
|
<LabelAndError>
|
|
|
|
|
<Label for="email">Email address</Label>
|
|
|
|
|
<FieldError v-if="errorMessage">{{ errorMessage }}</FieldError>
|
|
|
|
|
</LabelAndError>
|
|
|
|
|
<TextInput id="email" type="email" placeholder="joseph.jones@gmail.com" required v-bind="field"
|
2024-06-16 08:35:20 +02:00
|
|
|
:disabled="isLoading" :is-invalid="!!errorMessage" autocomplete="email" />
|
2024-06-21 04:09:09 +02:00
|
|
|
</Field>
|
2024-06-15 23:18:58 +02:00
|
|
|
</VeeField>
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2024-06-16 08:35:20 +02:00
|
|
|
<VeeField name="password" v-slot="{ errorMessage, field }" validate-on-change>
|
2024-06-21 04:09:09 +02:00
|
|
|
<Field>
|
|
|
|
|
<LabelAndError>
|
|
|
|
|
<Label for="password">Password</Label>
|
|
|
|
|
<FieldError v-if="errorMessage">{{ errorMessage }}</FieldError>
|
|
|
|
|
</LabelAndError>
|
|
|
|
|
<PasswordInput id="password" placeholder="hunter2" required v-bind="field" :disabled="isLoading"
|
|
|
|
|
:is-invalid="!!errorMessage" :show-strength="true" autocomplete="new-password" />
|
|
|
|
|
</Field>
|
2024-06-15 23:18:58 +02:00
|
|
|
</VeeField>
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2024-06-16 08:35:20 +02:00
|
|
|
<VeeField name="password-confirm" v-slot="{ errorMessage, field }" validate-on-change>
|
2024-06-21 04:09:09 +02:00
|
|
|
<Field>
|
|
|
|
|
<LabelAndError>
|
|
|
|
|
<Label for="password-confirm">Confirm password</Label>
|
|
|
|
|
<FieldError v-if="errorMessage">{{ errorMessage }}</FieldError>
|
|
|
|
|
</LabelAndError>
|
|
|
|
|
<PasswordInput id="password-confirm" placeholder="hunter2" required v-bind="field"
|
2024-06-16 08:35:20 +02:00
|
|
|
:disabled="isLoading" :is-invalid="!!errorMessage" autocomplete="new-password" />
|
2024-06-21 04:09:09 +02:00
|
|
|
</Field>
|
2024-06-15 23:18:58 +02:00
|
|
|
</VeeField>
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2024-06-16 08:35:20 +02:00
|
|
|
<VeeField name="tos" v-slot="{ errorMessage, field }" validate-on-change>
|
2024-06-21 04:09:09 +02:00
|
|
|
<Field>
|
2024-06-16 08:35:20 +02:00
|
|
|
<div class="flex flex-row gap-x-2 items-center">
|
2024-06-21 04:09:09 +02:00
|
|
|
<CheckboxInput :checked="true" id="tos" required :disabled="true" v-bind="field" />
|
|
|
|
|
<Label for="tos" class="!text-gray-200">
|
2024-06-16 08:35:20 +02:00
|
|
|
I agree to the Terms of Service
|
2024-06-21 04:09:09 +02:00
|
|
|
</Label>
|
2024-06-16 08:35:20 +02:00
|
|
|
</div>
|
2024-06-21 04:09:09 +02:00
|
|
|
<FieldError v-if="errorMessage">{{ errorMessage }}</FieldError>
|
|
|
|
|
</Field>
|
2024-06-15 23:18:58 +02:00
|
|
|
</VeeField>
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2024-06-16 08:35:20 +02:00
|
|
|
<Collapsible.Root>
|
|
|
|
|
<Collapsible.Trigger class="w-full">
|
2024-06-21 04:09:09 +02:00
|
|
|
<ButtonSecondary type="button" class="w-full">View Terms of Service</ButtonSecondary>
|
2024-06-16 08:35:20 +02:00
|
|
|
</Collapsible.Trigger>
|
|
|
|
|
<Collapsible.Content
|
|
|
|
|
class="prose prose-invert prose-sm p-4 ring-1 ring-white/10 bg-dark-700 rounded mt-3">
|
|
|
|
|
<div v-html="tos?.content"></div>
|
|
|
|
|
</Collapsible.Content>
|
|
|
|
|
</Collapsible.Root>
|
|
|
|
|
|
|
|
|
|
<p class="text-xs font-semibold text-gray-300">
|
|
|
|
|
Passwords are stored securely and hashed. We do not store your password in plain text.
|
|
|
|
|
Administrators
|
|
|
|
|
cannot see your password.
|
|
|
|
|
</p>
|
|
|
|
|
|
2024-06-21 04:09:09 +02:00
|
|
|
<ButtonPrimary type="submit" class="w-full" :disabled="isLoading">{{ isLoading ? "Registering..." :
|
|
|
|
|
"Register" }}</ButtonPrimary>
|
2024-06-15 23:18:58 +02:00
|
|
|
</VeeForm>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else>
|
|
|
|
|
<h1 class="text-2xl font-bold tracking-tight text-gray-50 sm:text-4xl text-center">Registrations are
|
|
|
|
|
disabled
|
|
|
|
|
</h1>
|
|
|
|
|
<p class="mt-6 text-lg leading-8 text-gray-200 text-center">Ask this instance's admin to enable them in
|
|
|
|
|
config!
|
|
|
|
|
</p>
|
2024-04-15 03:16:57 +02:00
|
|
|
</div>
|
2024-06-15 23:18:58 +02:00
|
|
|
</div>
|
2024-04-15 03:16:57 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2024-06-16 08:35:20 +02:00
|
|
|
import { Collapsible } from "@ark-ui/vue";
|
|
|
|
|
import type { ResponseError } from "@lysand-org/client";
|
2024-04-25 08:56:01 +02:00
|
|
|
import { toTypedSchema } from "@vee-validate/zod";
|
|
|
|
|
import { z } from "zod";
|
2024-06-21 04:09:09 +02:00
|
|
|
import ButtonPrimary from "~/components/buttons/button-primary.vue";
|
|
|
|
|
import ButtonSecondary from "~/components/buttons/button-secondary.vue";
|
|
|
|
|
import CheckboxInput from "~/components/inputs/checkbox-input.vue";
|
|
|
|
|
import FieldError from "~/components/inputs/field-error.vue";
|
|
|
|
|
import Field from "~/components/inputs/field.vue";
|
|
|
|
|
import LabelAndError from "~/components/inputs/label-and-error.vue";
|
|
|
|
|
import Label from "~/components/inputs/label.vue";
|
|
|
|
|
import PasswordInput from "~/components/inputs/password-input.vue";
|
|
|
|
|
import TextInput from "~/components/inputs/text-input.vue";
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2024-04-25 08:56:01 +02:00
|
|
|
const schema = toTypedSchema(
|
|
|
|
|
z
|
|
|
|
|
.object({
|
|
|
|
|
email: z.string().email(),
|
2024-06-16 08:35:20 +02:00
|
|
|
password: z.string().min(3).max(255),
|
|
|
|
|
"password-confirm": z.string().min(3).max(255),
|
2024-04-25 08:56:01 +02:00
|
|
|
username: z
|
|
|
|
|
.string()
|
|
|
|
|
.min(3)
|
2024-06-16 08:35:20 +02:00
|
|
|
.regex(
|
|
|
|
|
/^[a-z0-9_]+$/,
|
|
|
|
|
"Must be lowercase letters, numbers, or underscores",
|
|
|
|
|
),
|
2024-04-25 08:56:01 +02:00
|
|
|
reason: z.string().optional(),
|
|
|
|
|
})
|
|
|
|
|
.superRefine((data, ctx) => {
|
2024-06-16 08:35:20 +02:00
|
|
|
if (data.password !== data["password-confirm"]) {
|
2024-04-25 08:56:01 +02:00
|
|
|
ctx.addIssue({
|
2024-06-16 08:35:20 +02:00
|
|
|
path: [...ctx.path, "password-confirm"],
|
2024-04-25 08:56:01 +02:00
|
|
|
code: "custom",
|
|
|
|
|
message: "Passwords do not match",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}),
|
|
|
|
|
);
|
2024-04-15 03:16:57 +02:00
|
|
|
|
2024-06-08 01:09:15 +02:00
|
|
|
const client = useClient();
|
2024-06-16 08:35:20 +02:00
|
|
|
const tos = useTos(client);
|
2024-04-15 03:16:57 +02:00
|
|
|
|
|
|
|
|
const errors = ref<{
|
2024-06-16 08:35:20 +02:00
|
|
|
error?: string;
|
2024-04-15 03:16:57 +02:00
|
|
|
}>({});
|
|
|
|
|
|
2024-04-22 09:38:51 +02:00
|
|
|
const isLoading = ref(false);
|
2024-04-15 03:16:57 +02:00
|
|
|
|
2024-04-22 09:38:51 +02:00
|
|
|
const register = (result: {
|
|
|
|
|
username: string;
|
|
|
|
|
email: string;
|
|
|
|
|
password: string;
|
|
|
|
|
reason: string;
|
|
|
|
|
}) => {
|
|
|
|
|
isLoading.value = true;
|
2024-04-27 06:50:30 +02:00
|
|
|
ref(client)
|
|
|
|
|
.value?.registerAccount(
|
|
|
|
|
result.username,
|
|
|
|
|
result.email,
|
|
|
|
|
result.password,
|
|
|
|
|
true,
|
|
|
|
|
"en",
|
|
|
|
|
result.reason || "Empty reason",
|
|
|
|
|
)
|
2024-06-20 02:07:56 +02:00
|
|
|
.then(() => {
|
2024-04-22 09:38:51 +02:00
|
|
|
navigateTo("/register/success");
|
2024-04-15 03:16:57 +02:00
|
|
|
})
|
2024-06-20 02:07:56 +02:00
|
|
|
.catch((e) => {
|
2024-06-16 08:35:20 +02:00
|
|
|
const error = e as ResponseError<{
|
|
|
|
|
error: string;
|
|
|
|
|
}>;
|
2024-04-22 09:38:51 +02:00
|
|
|
// @ts-ignore
|
2024-06-16 08:35:20 +02:00
|
|
|
errors.value = error.response.data || {};
|
2024-04-25 08:56:01 +02:00
|
|
|
})
|
|
|
|
|
.finally(() => {
|
2024-04-22 09:38:51 +02:00
|
|
|
isLoading.value = false;
|
2024-04-15 03:16:57 +02:00
|
|
|
});
|
2024-04-25 08:56:01 +02:00
|
|
|
};
|
2024-06-16 08:35:20 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
@keyframes slideDown {
|
|
|
|
|
from {
|
|
|
|
|
height: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
to {
|
|
|
|
|
height: var(--height);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@keyframes slideUp {
|
|
|
|
|
from {
|
|
|
|
|
height: var(--height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
to {
|
|
|
|
|
height: 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[data-scope='collapsible'][data-part='content'][data-state='open'] {
|
|
|
|
|
animation: slideDown 250ms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[data-scope='collapsible'][data-part='content'][data-state='closed'] {
|
|
|
|
|
animation: slideUp 200ms;
|
|
|
|
|
}
|
|
|
|
|
</style>
|