2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
2022-07-12 10:55:28 +02:00
|
|
|
<section class="container mx-auto">
|
|
|
|
<h1>
|
|
|
|
{{ t("Forgot your password?") }}
|
|
|
|
</h1>
|
|
|
|
<p>
|
|
|
|
{{
|
|
|
|
t(
|
|
|
|
"Enter your email address below, and we'll email you instructions on how to change your password."
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</p>
|
|
|
|
<o-notification
|
|
|
|
title="Error"
|
|
|
|
variant="danger"
|
|
|
|
v-for="error in errors"
|
|
|
|
:key="error"
|
|
|
|
@close="removeError(error)"
|
|
|
|
>
|
|
|
|
{{ error }}
|
|
|
|
</o-notification>
|
|
|
|
<form @submit="sendResetPasswordTokenAction" v-if="!validationSent">
|
|
|
|
<o-field :label="t('Email address')">
|
|
|
|
<o-input
|
|
|
|
aria-required="true"
|
|
|
|
required
|
|
|
|
type="email"
|
|
|
|
v-model="credentials.email"
|
|
|
|
/>
|
|
|
|
</o-field>
|
|
|
|
<p class="control">
|
|
|
|
<o-button variant="primary" native-type="submit">
|
|
|
|
{{ t("Submit") }}
|
|
|
|
</o-button>
|
|
|
|
<router-link :to="{ name: RouteName.LOGIN }" class="button is-text">{{
|
|
|
|
t("Cancel")
|
|
|
|
}}</router-link>
|
|
|
|
</p>
|
|
|
|
</form>
|
|
|
|
<div v-else>
|
|
|
|
<o-notification variant="success" :closable="false" title="Success">
|
|
|
|
{{
|
|
|
|
t("We just sent an email to {email}", {
|
|
|
|
email: credentials.email,
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
</o-notification>
|
|
|
|
<o-notification variant="info">
|
|
|
|
{{
|
|
|
|
t("Please check your spam folder if you didn't receive the email.")
|
|
|
|
}}
|
|
|
|
</o-notification>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
2020-02-18 08:57:00 +01:00
|
|
|
import { SEND_RESET_PASSWORD } from "../../graphql/auth";
|
2020-06-18 16:01:14 +02:00
|
|
|
import RouteName from "../../router/name";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { computed, reactive, ref } from "vue";
|
|
|
|
import { useMutation } from "@vue/apollo-composable";
|
|
|
|
import { useHead } from "@vueuse/head";
|
|
|
|
import { useI18n } from "vue-i18n";
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { t } = useI18n({ useScope: "global" });
|
|
|
|
useHead({
|
|
|
|
title: computed(() => t("Reset password")),
|
|
|
|
});
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
email?: string;
|
|
|
|
}>(),
|
|
|
|
{ email: "" }
|
|
|
|
);
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const credentials = reactive<{ email: string }>({
|
|
|
|
email: props.email,
|
|
|
|
});
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const validationSent = ref(false);
|
2020-06-18 16:01:14 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const errors = ref<string[]>([]);
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const removeError = (message: string): void => {
|
|
|
|
errors.value.splice(errors.value.indexOf(message));
|
|
|
|
};
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const {
|
|
|
|
mutate: sendResetPasswordMutation,
|
|
|
|
onDone: sendResetPasswordDone,
|
|
|
|
onError: sendResetPasswordError,
|
|
|
|
} = useMutation(SEND_RESET_PASSWORD);
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
sendResetPasswordDone(() => {
|
|
|
|
validationSent.value = true;
|
|
|
|
});
|
|
|
|
sendResetPasswordError((err) => {
|
|
|
|
console.error(err);
|
|
|
|
if (err.graphQLErrors) {
|
|
|
|
err.graphQLErrors.forEach(({ message }: { message: string }) => {
|
|
|
|
if (errors.value.indexOf(message) < 0) {
|
|
|
|
errors.value.push(message);
|
2021-09-29 18:20:33 +02:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const sendResetPasswordTokenAction = async (e: Event): Promise<void> => {
|
|
|
|
e.preventDefault();
|
2019-10-10 14:20:09 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
sendResetPasswordMutation({
|
|
|
|
email: credentials.email,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
</script>
|