2022-09-01 22:32:03 +00:00
|
|
|
<script setup lang="ts">
|
2024-04-28 16:42:37 +00:00
|
|
|
import { useRouteHash } from "@vueuse/router";
|
2024-03-01 01:20:18 +00:00
|
|
|
import MdiGithub from "~icons/mdi/github";
|
|
|
|
import MdiTwitter from "~icons/mdi/twitter";
|
|
|
|
import MdiDiscord from "~icons/mdi/discord";
|
|
|
|
import MdiFolder from "~icons/mdi/folder";
|
|
|
|
import MdiAccount from "~icons/mdi/account";
|
|
|
|
import MdiAccountPlus from "~icons/mdi/account-plus";
|
|
|
|
import MdiLogin from "~icons/mdi/login";
|
|
|
|
import MdiArrowRight from "~icons/mdi/arrow-right";
|
|
|
|
import MdiLock from "~icons/mdi/lock";
|
|
|
|
|
2024-04-28 16:42:37 +00:00
|
|
|
enum PageForms {
|
|
|
|
Register = "register",
|
|
|
|
Login = "login",
|
|
|
|
ForgotPassword = "forgot-password",
|
|
|
|
}
|
|
|
|
|
2022-09-01 22:32:03 +00:00
|
|
|
useHead({
|
2022-09-09 22:46:53 +00:00
|
|
|
title: "Homebox | Organize and Tag Your Stuff",
|
2022-09-01 22:32:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
definePageMeta({
|
2022-09-09 22:46:53 +00:00
|
|
|
layout: "empty",
|
2023-10-07 03:44:43 +00:00
|
|
|
middleware: [
|
|
|
|
() => {
|
|
|
|
const ctx = useAuthContext();
|
|
|
|
if (ctx.isAuthorized()) {
|
|
|
|
return "/home";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
],
|
2022-09-01 22:32:03 +00:00
|
|
|
});
|
|
|
|
|
2023-02-18 06:57:21 +00:00
|
|
|
const ctx = useAuthContext();
|
|
|
|
|
2022-09-25 22:33:13 +00:00
|
|
|
const api = usePublicApi();
|
|
|
|
const toast = useNotifier();
|
|
|
|
|
2024-04-28 16:42:37 +00:00
|
|
|
const pageForm = useRouteHash(PageForms.Login);
|
|
|
|
const pageFormStr = computed(() => (pageForm.value[0] === "#" ? pageForm.value.slice(1) : pageForm.value));
|
|
|
|
|
2022-10-12 20:53:22 +00:00
|
|
|
const { data: status } = useAsyncData(async () => {
|
|
|
|
const { data } = await api.status();
|
|
|
|
|
2022-10-30 02:15:35 +00:00
|
|
|
if (data.demo) {
|
2022-10-13 05:13:07 +00:00
|
|
|
username.value = "demo@example.com";
|
2022-10-12 20:53:22 +00:00
|
|
|
password.value = "demo";
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
});
|
|
|
|
|
|
|
|
whenever(status, status => {
|
|
|
|
if (status?.demo) {
|
2022-10-13 05:13:07 +00:00
|
|
|
email.value = "demo@example.com";
|
2022-10-12 20:53:22 +00:00
|
|
|
loginPassword.value = "demo";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
const route = useRoute();
|
|
|
|
const router = useRouter();
|
|
|
|
|
2022-09-25 22:33:13 +00:00
|
|
|
const username = ref("");
|
|
|
|
const email = ref("");
|
|
|
|
const password = ref("");
|
|
|
|
const canRegister = ref(false);
|
2023-03-23 05:52:25 +00:00
|
|
|
const remember = ref(false);
|
2022-09-01 22:32:03 +00:00
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
const groupToken = computed<string>({
|
|
|
|
get() {
|
|
|
|
const params = route.query.token;
|
|
|
|
|
|
|
|
if (typeof params === "string") {
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
},
|
|
|
|
set(v) {
|
|
|
|
router.push({
|
|
|
|
query: {
|
|
|
|
token: v,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-09-01 22:32:03 +00:00
|
|
|
async function registerUser() {
|
|
|
|
loading.value = true;
|
2022-09-04 06:19:13 +00:00
|
|
|
const { error } = await api.register({
|
2022-09-27 23:52:13 +00:00
|
|
|
name: username.value,
|
|
|
|
email: email.value,
|
|
|
|
password: password.value,
|
2022-10-07 02:54:09 +00:00
|
|
|
token: groupToken.value,
|
2022-09-01 22:32:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
2022-09-09 22:46:53 +00:00
|
|
|
toast.error("Problem registering user");
|
2022-09-04 06:19:13 +00:00
|
|
|
return;
|
2022-09-01 22:32:03 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 22:46:53 +00:00
|
|
|
toast.success("User registered");
|
2022-09-04 06:19:13 +00:00
|
|
|
|
2022-09-01 22:32:03 +00:00
|
|
|
loading.value = false;
|
2024-04-28 16:42:37 +00:00
|
|
|
pageForm.value = PageForms.Login;
|
2022-09-01 22:32:03 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
onMounted(() => {
|
|
|
|
if (groupToken.value !== "") {
|
2024-04-28 16:42:37 +00:00
|
|
|
pageForm.value = PageForms.Register;
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-09-01 22:32:03 +00:00
|
|
|
const loading = ref(false);
|
2022-09-25 22:33:13 +00:00
|
|
|
const loginPassword = ref("");
|
2022-09-01 22:32:03 +00:00
|
|
|
|
|
|
|
async function login() {
|
|
|
|
loading.value = true;
|
2023-03-23 05:52:25 +00:00
|
|
|
const { error } = await ctx.login(api, email.value, loginPassword.value, remember.value);
|
2022-09-01 22:32:03 +00:00
|
|
|
|
|
|
|
if (error) {
|
2022-09-09 22:46:53 +00:00
|
|
|
toast.error("Invalid email or password");
|
2022-09-25 22:33:13 +00:00
|
|
|
loading.value = false;
|
|
|
|
return;
|
|
|
|
}
|
2022-09-01 22:32:03 +00:00
|
|
|
|
2022-09-25 22:33:13 +00:00
|
|
|
toast.success("Logged in successfully");
|
2022-09-01 22:32:03 +00:00
|
|
|
|
2022-09-25 22:33:13 +00:00
|
|
|
navigateTo("/home");
|
2022-09-01 22:32:03 +00:00
|
|
|
loading.value = false;
|
|
|
|
}
|
|
|
|
|
2024-04-28 16:42:37 +00:00
|
|
|
async function resetPassword() {
|
|
|
|
if (email.value === "") {
|
|
|
|
toast.error("Email is required");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const resp = await api.resetPasseord(email.value);
|
|
|
|
if (resp.error) {
|
|
|
|
toast.error("Problem resetting password");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
toast.success("Password reset link sent to your email");
|
|
|
|
return await Promise.resolve();
|
|
|
|
}
|
2022-09-01 22:32:03 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-02-18 19:09:19 +00:00
|
|
|
<div class="flex flex-col min-h-screen">
|
2022-09-05 00:37:37 +00:00
|
|
|
<div class="fill-primary min-w-full absolute top-0 z-[-1]">
|
|
|
|
<div class="bg-primary flex-col flex min-h-[20vh]" />
|
|
|
|
<svg
|
|
|
|
class="fill-primary drop-shadow-xl"
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
viewBox="0 0 1440 320"
|
|
|
|
preserveAspectRatio="none"
|
|
|
|
>
|
|
|
|
<path
|
|
|
|
fill-opacity="1"
|
|
|
|
d="M0,32L80,69.3C160,107,320,181,480,181.3C640,181,800,107,960,117.3C1120,128,1280,224,1360,272L1440,320L1440,0L1360,0C1280,0,1120,0,960,0C800,0,640,0,480,0C320,0,160,0,80,0L0,0Z"
|
|
|
|
></path>
|
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<header class="p-4 sm:px-6 lg:p-14 sm:py-6 sm:flex sm:items-end mx-auto">
|
|
|
|
<div>
|
|
|
|
<h2 class="mt-1 text-4xl font-bold tracking-tight text-neutral-content sm:text-5xl lg:text-6xl flex">
|
|
|
|
HomeB
|
2022-09-12 22:47:27 +00:00
|
|
|
<AppLogo class="w-12 -mb-4" />
|
2022-09-05 00:37:37 +00:00
|
|
|
x
|
|
|
|
</h2>
|
2023-03-24 03:10:19 +00:00
|
|
|
<p class="ml-1 text-lg text-base-content/50">Track, Organize, and Manage your Things.</p>
|
2022-09-05 00:37:37 +00:00
|
|
|
</div>
|
|
|
|
<div class="flex mt-6 sm:mt-0 gap-4 ml-auto text-neutral-content">
|
|
|
|
<a class="tooltip" data-tip="Project Github" href="https://github.com/hay-kot/homebox" target="_blank">
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiGithub class="h-8 w-8" />
|
2022-09-05 00:37:37 +00:00
|
|
|
</a>
|
|
|
|
<a href="https://twitter.com/haybytes" class="tooltip" data-tip="Follow The Developer" target="_blank">
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiTwitter class="h-8 w-8" />
|
2022-09-05 00:37:37 +00:00
|
|
|
</a>
|
2022-10-14 16:30:23 +00:00
|
|
|
<a href="https://discord.gg/tuncmNrE4z" class="tooltip" data-tip="Join The Discord" target="_blank">
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiDiscord class="h-8 w-8" />
|
2022-09-05 00:37:37 +00:00
|
|
|
</a>
|
2022-10-14 16:30:23 +00:00
|
|
|
<a href="https://hay-kot.github.io/homebox/" class="tooltip" data-tip="Read The Docs" target="_blank">
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiFolder class="h-8 w-8" />
|
2022-09-05 00:37:37 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
<div class="grid p-6 sm:place-items-center min-h-[50vh]">
|
|
|
|
<div>
|
|
|
|
<Transition name="slide-fade">
|
2024-04-28 16:42:37 +00:00
|
|
|
<form v-if="pageFormStr === PageForms.Register" @submit.prevent="registerUser">
|
2022-09-05 00:37:37 +00:00
|
|
|
<div class="card w-max-[500px] md:w-[500px] bg-base-100 shadow-xl">
|
|
|
|
<div class="card-body">
|
|
|
|
<h2 class="card-title text-2xl align-center">
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiAccount class="mr-1 w-7 h-7" />
|
2022-09-04 06:19:13 +00:00
|
|
|
Register
|
2022-09-05 00:37:37 +00:00
|
|
|
</h2>
|
2022-09-25 22:33:13 +00:00
|
|
|
<FormTextField v-model="email" label="Set your email?" />
|
|
|
|
<FormTextField v-model="username" label="What's your name?" />
|
2022-10-09 13:03:24 +00:00
|
|
|
<div v-if="!(groupToken == '')" class="pt-4 pb-1 text-center">
|
2022-10-07 02:54:09 +00:00
|
|
|
<p>You're Joining an Existing Group!</p>
|
|
|
|
<button type="button" class="text-xs underline" @click="groupToken = ''">
|
|
|
|
Don't Want To Join a Group?
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-02-05 21:56:47 +00:00
|
|
|
<FormPassword v-model="password" label="Set your password" />
|
2022-09-25 22:33:13 +00:00
|
|
|
<PasswordScore v-model:valid="canRegister" :password="password" />
|
2022-09-05 00:37:37 +00:00
|
|
|
<div class="card-actions justify-end">
|
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
class="btn btn-primary mt-2"
|
|
|
|
:class="loading ? 'loading' : ''"
|
2022-09-25 22:33:13 +00:00
|
|
|
:disabled="loading || !canRegister"
|
2022-09-05 00:37:37 +00:00
|
|
|
>
|
|
|
|
Register
|
|
|
|
</button>
|
|
|
|
</div>
|
2022-09-04 06:19:13 +00:00
|
|
|
</div>
|
2022-09-01 22:32:03 +00:00
|
|
|
</div>
|
2022-09-05 00:37:37 +00:00
|
|
|
</form>
|
2024-04-28 16:42:37 +00:00
|
|
|
<form v-else-if="pageFormStr === PageForms.ForgotPassword" @submit.prevent="resetPassword">
|
|
|
|
<div class="card w-max-[500px] md:w-[500px] bg-base-100 shadow-xl">
|
|
|
|
<div class="card-body">
|
|
|
|
<h2 class="card-title text-2xl align-center">
|
|
|
|
<MdiAccount class="mr-1 w-7 h-7" />
|
|
|
|
Reset Password
|
|
|
|
</h2>
|
|
|
|
<FormTextField v-model="email" label="Email" />
|
|
|
|
<p class="text-sm text-base-content/50">
|
|
|
|
If you have an account with us, we will send you a password reset link.
|
|
|
|
</p>
|
|
|
|
<div class="card-actions justify-end mt-4">
|
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
class="btn btn-primary btn-block"
|
|
|
|
:class="loading ? 'loading' : ''"
|
|
|
|
:disabled="loading"
|
|
|
|
>
|
|
|
|
Reset Password
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
2022-09-05 00:37:37 +00:00
|
|
|
<form v-else @submit.prevent="login">
|
|
|
|
<div class="card w-max-[500px] md:w-[500px] bg-base-100 shadow-xl">
|
|
|
|
<div class="card-body">
|
|
|
|
<h2 class="card-title text-2xl align-center">
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiAccount class="mr-1 w-7 h-7" />
|
2022-09-04 06:19:13 +00:00
|
|
|
Login
|
2022-09-05 00:37:37 +00:00
|
|
|
</h2>
|
2022-10-12 20:53:22 +00:00
|
|
|
<template v-if="status && status.demo">
|
|
|
|
<p class="text-xs italic text-center">This is a demo instance</p>
|
2022-10-13 05:13:07 +00:00
|
|
|
<p class="text-xs text-center"><b>Email</b> demo@example.com</p>
|
2022-10-12 20:53:22 +00:00
|
|
|
<p class="text-xs text-center"><b>Password</b> demo</p>
|
|
|
|
</template>
|
2022-09-25 22:33:13 +00:00
|
|
|
<FormTextField v-model="email" label="Email" />
|
2023-02-05 21:56:47 +00:00
|
|
|
<FormPassword v-model="loginPassword" label="Password" />
|
2023-03-23 05:52:25 +00:00
|
|
|
<div class="max-w-[140px]">
|
|
|
|
<FormCheckbox v-model="remember" label="Remember Me" />
|
|
|
|
</div>
|
|
|
|
<div class="card-actions justify-end">
|
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
class="btn btn-primary btn-block"
|
|
|
|
:class="loading ? 'loading' : ''"
|
|
|
|
:disabled="loading"
|
|
|
|
>
|
2022-09-05 00:37:37 +00:00
|
|
|
Login
|
|
|
|
</button>
|
|
|
|
</div>
|
2022-09-04 06:19:13 +00:00
|
|
|
</div>
|
2022-09-01 22:32:03 +00:00
|
|
|
</div>
|
2022-09-05 00:37:37 +00:00
|
|
|
</form>
|
|
|
|
</Transition>
|
|
|
|
<div class="text-center mt-6">
|
2023-02-16 19:28:52 +00:00
|
|
|
<BaseButton
|
2023-02-15 17:58:38 +00:00
|
|
|
v-if="status && status.allowRegistration"
|
2023-02-16 19:28:52 +00:00
|
|
|
class="btn-primary btn-wide"
|
2024-04-28 16:42:37 +00:00
|
|
|
:to="pageFormStr === PageForms.Register ? `#${PageForms.Login}` : `#${PageForms.Register}`"
|
2022-09-05 00:37:37 +00:00
|
|
|
>
|
2023-02-16 19:28:52 +00:00
|
|
|
<template #icon>
|
2024-04-28 16:42:37 +00:00
|
|
|
<MdiAccountPlus v-if="pageFormStr === PageForms.Register" class="w-5 h-5 swap-off" />
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiLogin v-else class="w-5 h-5 swap-off" />
|
|
|
|
<MdiArrowRight class="w-5 h-5 swap-on" />
|
2023-02-16 19:28:52 +00:00
|
|
|
</template>
|
2024-04-28 16:42:37 +00:00
|
|
|
{{ pageFormStr === PageForms.Register ? "Login" : "Register" }}
|
2023-02-16 19:28:52 +00:00
|
|
|
</BaseButton>
|
|
|
|
<p v-else class="text-base-content italic text-sm inline-flex items-center gap-2">
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiLock class="w-4 h-4 inline-block" />
|
2023-02-16 19:28:52 +00:00
|
|
|
Registration Disabled
|
|
|
|
</p>
|
2024-04-28 16:42:37 +00:00
|
|
|
<NuxtLink :to="`#${PageForms.ForgotPassword}`">
|
|
|
|
<p class="text-xs text-base-content/50 mt-2">Forgot your password?</p>
|
|
|
|
</NuxtLink>
|
2022-09-05 00:37:37 +00:00
|
|
|
</div>
|
2022-09-01 22:32:03 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-18 19:09:19 +00:00
|
|
|
<footer v-if="status" class="mt-auto text-center w-full bottom-0 pb-4">
|
2022-10-14 00:49:29 +00:00
|
|
|
<p class="text-center text-sm">Version: {{ status.build.version }} ~ Build: {{ status.build.commit }}</p>
|
|
|
|
</footer>
|
2022-09-01 22:32:03 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="css" scoped>
|
|
|
|
.slide-fade-enter-active {
|
|
|
|
transition: all 0.2s ease-out;
|
|
|
|
}
|
|
|
|
|
|
|
|
.slide-fade-enter-from,
|
|
|
|
.slide-fade-leave-to {
|
|
|
|
position: absolute;
|
|
|
|
transform: translateX(20px);
|
|
|
|
opacity: 0;
|
|
|
|
}
|
2022-09-25 22:33:13 +00:00
|
|
|
|
|
|
|
progress[value]::-webkit-progress-value {
|
|
|
|
transition: width 0.5s;
|
|
|
|
}
|
2022-09-01 22:32:03 +00:00
|
|
|
</style>
|