2022-09-01 22:32:03 +00:00
|
|
|
<script setup lang="ts">
|
2022-09-09 22:46:53 +00:00
|
|
|
import { useAuthStore } from "~~/stores/auth";
|
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",
|
2022-09-01 22:32:03 +00:00
|
|
|
});
|
|
|
|
|
2022-09-25 22:33:13 +00:00
|
|
|
const api = usePublicApi();
|
|
|
|
const toast = useNotifier();
|
|
|
|
|
2022-09-03 09:17:57 +00:00
|
|
|
const authStore = useAuthStore();
|
|
|
|
if (!authStore.isTokenExpired) {
|
2022-09-09 22:46:53 +00:00
|
|
|
navigateTo("/home");
|
2022-09-03 09:17:57 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 05:36:51 +00:00
|
|
|
const route = useRoute();
|
|
|
|
const router = useRouter();
|
|
|
|
|
2022-09-25 22:33:13 +00:00
|
|
|
const username = ref("");
|
|
|
|
const email = ref("");
|
|
|
|
const groupName = ref("");
|
|
|
|
const password = ref("");
|
|
|
|
const canRegister = ref(false);
|
2022-09-01 22:32:03 +00:00
|
|
|
|
2022-10-04 05:36:51 +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-09-25 22:33:13 +00:00
|
|
|
groupName: groupName.value,
|
2022-10-04 05:36:51 +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;
|
2022-09-04 06:19:13 +00:00
|
|
|
registerForm.value = false;
|
2022-09-01 22:32:03 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 05:36:51 +00:00
|
|
|
onMounted(() => {
|
|
|
|
console.log(groupToken.value);
|
|
|
|
if (groupToken.value !== "") {
|
|
|
|
registerForm.value = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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;
|
2022-09-25 22:33:13 +00:00
|
|
|
const { data, error } = await api.login(email.value, loginPassword.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-10-04 05:36:51 +00:00
|
|
|
// @ts-expect-error - expires is either a date or a string, need to figure out store typing
|
2022-09-25 22:33:13 +00:00
|
|
|
authStore.$patch({
|
|
|
|
token: data.token,
|
|
|
|
expires: data.expiresAt,
|
|
|
|
});
|
|
|
|
|
|
|
|
navigateTo("/home");
|
2022-09-01 22:32:03 +00:00
|
|
|
loading.value = false;
|
|
|
|
}
|
|
|
|
|
2022-09-25 22:33:13 +00:00
|
|
|
const [registerForm, toggleLogin] = useToggle();
|
2022-09-01 22:32:03 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
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>
|
|
|
|
<p class="ml-1 text-lg text-base-content/50">Track, Organize, and Manage your Shit.</p>
|
|
|
|
</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">
|
|
|
|
<Icon name="mdi-github" class="h-8 w-8" />
|
|
|
|
</a>
|
|
|
|
<a href="https://twitter.com/haybytes" class="tooltip" data-tip="Follow The Developer" target="_blank">
|
|
|
|
<Icon name="mdi-twitter" class="h-8 w-8" />
|
|
|
|
</a>
|
2022-09-06 18:32:13 +00:00
|
|
|
<a href="https://discord.gg/tuncmNrE4z" class="tooltip" data-tip="Join The Discord">
|
2022-09-05 00:37:37 +00:00
|
|
|
<Icon name="mdi-discord" class="h-8 w-8" />
|
|
|
|
</a>
|
2022-09-06 18:32:13 +00:00
|
|
|
<a href="https://github.com/hay-kot/homebox" class="tooltip" data-tip="Read The Docs">
|
2022-09-05 00:37:37 +00:00
|
|
|
<Icon name="mdi-folder" class="h-8 w-8" />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
<div class="grid p-6 sm:place-items-center min-h-[50vh]">
|
|
|
|
<div>
|
|
|
|
<Transition name="slide-fade">
|
|
|
|
<form v-if="registerForm" @submit.prevent="registerUser">
|
|
|
|
<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">
|
|
|
|
<Icon name="heroicons-user" 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-04 05:36:51 +00:00
|
|
|
<FormTextField v-if="groupToken == ''" v-model="groupName" label="Name your group" />
|
|
|
|
<div v-else class="pt-4 pb-1 text-center">
|
|
|
|
<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>
|
2022-09-25 22:33:13 +00:00
|
|
|
<FormTextField v-model="password" label="Set your password" type="password" />
|
|
|
|
<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>
|
|
|
|
<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">
|
|
|
|
<Icon name="heroicons-user" 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-09-25 22:33:13 +00:00
|
|
|
<FormTextField v-model="email" label="Email" />
|
|
|
|
<FormTextField v-model="loginPassword" label="Password" type="password" />
|
2022-09-05 00:37:37 +00:00
|
|
|
<div class="card-actions justify-end mt-2">
|
|
|
|
<button type="submit" class="btn btn-primary" :class="loading ? 'loading' : ''" :disabled="loading">
|
|
|
|
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">
|
|
|
|
<button
|
|
|
|
class="text-base-content text-lg hover:bg-primary hover:text-primary-content px-3 py-1 rounded-xl transition-colors duration-200"
|
2022-09-25 22:33:13 +00:00
|
|
|
@click="() => toggleLogin()"
|
2022-09-05 00:37:37 +00:00
|
|
|
>
|
2022-09-09 22:46:53 +00:00
|
|
|
{{ registerForm ? "Already a User? Login" : "Not a User? Register" }}
|
2022-09-05 00:37:37 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
2022-09-01 22:32:03 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</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>
|