Merge pull request 'Implement password reset + minor changes to button component' (#42) from password-reset into main
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
Reviewed-on: #42 Reviewed-by: JustTemmie <git@beaver.mom>
This commit is contained in:
commit
5f2267a448
8 changed files with 172 additions and 7 deletions
|
@ -1,14 +1,14 @@
|
||||||
<template>
|
<template>
|
||||||
<div @click="props.callback()" class="button" :class="props.variant + '-button'">
|
<button @click="props.callback ? props.callback() : null" class="button" :class="props.variant + '-button'">
|
||||||
{{ props.text }}
|
{{ props.text }}
|
||||||
</div>
|
</button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
text: string,
|
text: string,
|
||||||
callback: CallableFunction,
|
callback?: CallableFunction,
|
||||||
variant?: "normal" | "scary" | "neutral",
|
variant?: "normal" | "scary" | "neutral",
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ const props = defineProps<{
|
||||||
border-radius: 0.7rem;
|
border-radius: 0.7rem;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
||||||
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button:hover {
|
.button:hover {
|
||||||
|
|
|
@ -79,6 +79,14 @@ export const useApi = () => {
|
||||||
await fetchWithApi("/auth/verify-email", { method: "POST", body: { email } });
|
await fetchWithApi("/auth/verify-email", { method: "POST", body: { email } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sendPasswordResetEmail(identifier: string): Promise<void> {
|
||||||
|
await fetchWithApi("/auth/reset-password", { method: "GET", query: { identifier } });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resetPassword(password: string, token: string) {
|
||||||
|
await fetchWithApi("/auth/reset-password", { method: "POST", body: { password, token } });
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fetchGuilds,
|
fetchGuilds,
|
||||||
fetchGuild,
|
fetchGuild,
|
||||||
|
@ -97,6 +105,8 @@ export const useApi = () => {
|
||||||
joinGuild,
|
joinGuild,
|
||||||
createChannel,
|
createChannel,
|
||||||
fetchInstanceStats,
|
fetchInstanceStats,
|
||||||
sendVerificationEmail
|
sendVerificationEmail,
|
||||||
|
sendPasswordResetEmail,
|
||||||
|
resetPassword
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div v-else id="auth-form-container">
|
<div v-else id="auth-form-container">
|
||||||
<slot />
|
<slot />
|
||||||
|
<div v-if="!['/recover', '/reset-password'].includes(route.path)">Forgot password? Recover <NuxtLink href="/recover">here</NuxtLink>!</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="instanceUrl">
|
<div v-if="instanceUrl">
|
||||||
Instance URL is set to <span style="color: var(--primary-color);">{{ instanceUrl }}</span>
|
Instance URL is set to <span style="color: var(--primary-color);">{{ instanceUrl }}</span>
|
||||||
|
@ -36,7 +37,11 @@ const apiVersion = useRuntimeConfig().public.apiVersion;
|
||||||
const apiBase = useCookie("api_base");
|
const apiBase = useCookie("api_base");
|
||||||
const registrationEnabled = useState("registrationEnabled", () => true);
|
const registrationEnabled = useState("registrationEnabled", () => true);
|
||||||
|
|
||||||
const auth = useAuth();
|
const route = useRoute();
|
||||||
|
|
||||||
|
const query = route.query as Record<string, string>;
|
||||||
|
const searchParams = new URLSearchParams(query);
|
||||||
|
searchParams.delete("token");
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
instanceUrl.value = useCookie("instance_url").value;
|
instanceUrl.value = useCookie("instance_url").value;
|
||||||
|
@ -111,6 +116,7 @@ const form = reactive({
|
||||||
#auth-form-container form {
|
#auth-form-container form {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
margin-top: 10dvh;
|
margin-top: 10dvh;
|
||||||
gap: 1em;
|
gap: 1em;
|
||||||
|
|
|
@ -16,7 +16,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (["/login", "/register"].includes(to.path) && !Object.keys(to.query).includes("special")) {
|
if (["/login", "/register", "/recover", "/reset-password"].includes(to.path) && !Object.keys(to.query).includes("special")) {
|
||||||
console.log("path is login or register");
|
console.log("path is login or register");
|
||||||
const apiBase = useCookie("api_base");
|
const apiBase = useCookie("api_base");
|
||||||
console.log("apiBase gotten:", apiBase.value);
|
console.log("apiBase gotten:", apiBase.value);
|
||||||
|
|
|
@ -36,6 +36,7 @@ const form = reactive({
|
||||||
|
|
||||||
const query = useRoute().query as Record<string, string>;
|
const query = useRoute().query as Record<string, string>;
|
||||||
const searchParams = new URLSearchParams(query);
|
const searchParams = new URLSearchParams(query);
|
||||||
|
searchParams.delete("token");
|
||||||
|
|
||||||
const registrationEnabled = ref<boolean>(true);
|
const registrationEnabled = ref<boolean>(true);
|
||||||
const apiBase = useCookie("api_base");
|
const apiBase = useCookie("api_base");
|
||||||
|
@ -48,7 +49,7 @@ if (apiBase.value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const registerUrl = `/register?${searchParams}`
|
const registerUrl = `/register?${searchParams}`;
|
||||||
|
|
||||||
const { login } = useAuth();
|
const { login } = useAuth();
|
||||||
|
|
||||||
|
|
89
pages/recover.vue
Normal file
89
pages/recover.vue
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
<template>
|
||||||
|
<NuxtLayout name="auth">
|
||||||
|
<div v-if="errorValue">{{ errorValue }}</div>
|
||||||
|
<form v-if="!emailFormSent" @submit.prevent="sendEmail">
|
||||||
|
<div>
|
||||||
|
<label for="identifier">Email or username</label>
|
||||||
|
<br>
|
||||||
|
<input type="text" name="identifier" id="identifier" v-model="emailForm.identifier">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Button type="submit" text="Send email" variant="normal" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div v-else>
|
||||||
|
If an account with that username or email exists, an email will be sent to it shortly.
|
||||||
|
</div>
|
||||||
|
<div v-if="registrationEnabled">
|
||||||
|
Don't have an account? <NuxtLink :href="registerUrl">Register</NuxtLink> one!
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
Already have an account? <NuxtLink :href="loginUrl">Log in</NuxtLink>!
|
||||||
|
</div>
|
||||||
|
</NuxtLayout>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import Button from '~/components/UserInterface/Button.vue';
|
||||||
|
|
||||||
|
const emailForm = reactive({
|
||||||
|
identifier: ""
|
||||||
|
});
|
||||||
|
|
||||||
|
const emailFormSent = ref(false);
|
||||||
|
|
||||||
|
const passwordForm = reactive({
|
||||||
|
password: ""
|
||||||
|
});
|
||||||
|
|
||||||
|
const errorValue = ref<string>();
|
||||||
|
|
||||||
|
const registrationEnabled = ref<boolean>(true);
|
||||||
|
const apiBase = useCookie("api_base");
|
||||||
|
|
||||||
|
const query = useRoute().query as Record<string, string>;
|
||||||
|
const searchParams = new URLSearchParams(query);
|
||||||
|
|
||||||
|
const token = ref(searchParams.get("token"))
|
||||||
|
searchParams.delete("token");
|
||||||
|
const { resetPassword } = useApi();
|
||||||
|
|
||||||
|
const registerUrl = `/register?${searchParams}`;
|
||||||
|
const loginUrl = `/login?${searchParams}`;
|
||||||
|
|
||||||
|
if (apiBase.value) {
|
||||||
|
console.log("apiBase:", apiBase.value);
|
||||||
|
const stats = await useApi().fetchInstanceStats(apiBase.value);
|
||||||
|
if (stats) {
|
||||||
|
registrationEnabled.value = stats.registration_enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { sendPasswordResetEmail } = useApi();
|
||||||
|
|
||||||
|
async function sendEmail() {
|
||||||
|
try {
|
||||||
|
await sendPasswordResetEmail(emailForm.identifier);
|
||||||
|
emailFormSent.value = true;
|
||||||
|
} catch (error) {
|
||||||
|
errorValue.value = (error as any).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendPassword() {
|
||||||
|
try {
|
||||||
|
console.log("pass:", passwordForm.password);
|
||||||
|
const hashedPass = await hashPassword(passwordForm.password)
|
||||||
|
console.log("hashed pass:", hashedPass);
|
||||||
|
await resetPassword(hashedPass, token.value!);
|
||||||
|
return await navigateTo(`/login?${searchParams}`);
|
||||||
|
} catch (error) {
|
||||||
|
errorValue.value = (error as any).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
|
@ -86,6 +86,7 @@ const auth = useAuth();
|
||||||
const loggedIn = ref(await auth.getUser());
|
const loggedIn = ref(await auth.getUser());
|
||||||
|
|
||||||
const query = new URLSearchParams(useRoute().query as Record<string, string>);
|
const query = new URLSearchParams(useRoute().query as Record<string, string>);
|
||||||
|
query.delete("token");
|
||||||
|
|
||||||
const user = await useAuth().getUser();
|
const user = await useAuth().getUser();
|
||||||
|
|
||||||
|
|
56
pages/reset-password.vue
Normal file
56
pages/reset-password.vue
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
<template>
|
||||||
|
<NuxtLayout name="auth">
|
||||||
|
<div v-if="errorValue">{{ errorValue }}</div>
|
||||||
|
<form @submit.prevent="sendPassword">
|
||||||
|
<div>
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<br>
|
||||||
|
<input type="password" name="password" id="password" v-model="passwordForm.password">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Button type="submit" text="Submit" variant="normal" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div>
|
||||||
|
Already have an account? <NuxtLink :href="loginUrl">Log in</NuxtLink>!
|
||||||
|
</div>
|
||||||
|
</NuxtLayout>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import Button from '~/components/UserInterface/Button.vue';
|
||||||
|
|
||||||
|
const query = useRoute().query as Record<string, string>;
|
||||||
|
const searchParams = new URLSearchParams(query);
|
||||||
|
|
||||||
|
const loginUrl = `/login?${searchParams}`;
|
||||||
|
|
||||||
|
const token = ref(searchParams.get("token"))
|
||||||
|
|
||||||
|
if (!token.value) await navigateTo("/login");
|
||||||
|
|
||||||
|
const passwordForm = reactive({
|
||||||
|
password: ""
|
||||||
|
});
|
||||||
|
|
||||||
|
const errorValue = ref<string>();
|
||||||
|
|
||||||
|
const { resetPassword } = useApi();
|
||||||
|
|
||||||
|
async function sendPassword() {
|
||||||
|
try {
|
||||||
|
console.log("pass:", passwordForm.password);
|
||||||
|
const hashedPass = await hashPassword(passwordForm.password)
|
||||||
|
console.log("hashed pass:", hashedPass);
|
||||||
|
await resetPassword(hashedPass, token.value!);
|
||||||
|
return await navigateTo("/login?");
|
||||||
|
} catch (error) {
|
||||||
|
errorValue.value = (error as any).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
Loading…
Add table
Add a link
Reference in a new issue