|
| 1 | +<script setup lang="ts"> |
| 2 | +import { reactive, ref } from "vue"; |
| 3 | +import { useTitle } from "@vueuse/core"; |
| 4 | +import { useI18n } from "vue-i18n"; |
| 5 | +import { useRouter } from "vue-router"; |
| 6 | +import useVuelidate from "@vuelidate/core"; |
| 7 | +import { email } from "@vuelidate/validators"; |
| 8 | +import api from "@/models/api"; |
| 9 | +
|
| 10 | +const router = useRouter(); |
| 11 | +
|
| 12 | +const rules = { |
| 13 | + email: { email }, |
| 14 | +}; |
| 15 | +
|
| 16 | +const form = reactive({ |
| 17 | + email: "", |
| 18 | +}); |
| 19 | +const v$ = useVuelidate(rules, form); |
| 20 | +
|
| 21 | +const { t } = useI18n(); |
| 22 | +
|
| 23 | +const showError = ref(false); |
| 24 | +const success = ref(false); |
| 25 | +
|
| 26 | +const handleSubmit = async () => { |
| 27 | + if (!v$.value.$validate()) return; |
| 28 | +
|
| 29 | + const checkEmail = await api.Auth.checkEmail({ email: form.email }); |
| 30 | + if (checkEmail.data.valid === 1) { |
| 31 | + showError.value = true; |
| 32 | + return; |
| 33 | + } |
| 34 | +
|
| 35 | + const res = await api.Auth.sendRecoveryEmail({ email: form.email }); |
| 36 | + if (res.statusText === "OK") { |
| 37 | + success.value = true; |
| 38 | + } |
| 39 | +}; |
| 40 | +
|
| 41 | +useTitle("Forgot Password"); |
| 42 | +</script> |
| 43 | + |
| 44 | +<template> |
| 45 | + <div class="mx-4 flex max-w-4xl flex-col items-center justify-center gap-4 p-4 md:mx-auto"> |
| 46 | + <h1 class="my-12 text-center text-4xl font-bold">{{ t("password_reset.forgot-password") }}</h1> |
| 47 | + <div class="card w-96 max-w-full bg-base-200 shadow-xl"> |
| 48 | + <div v-if="!success" class="card-body"> |
| 49 | + <div class="card-title flex-col"> |
| 50 | + <div v-if="showError" class="alert alert-error text-base"> |
| 51 | + {{ t("password_reset.status.error") }} |
| 52 | + <div class="flex-none"> |
| 53 | + <button @click="showError = false" class="btn btn-ghost btn-sm btn-circle">X</button> |
| 54 | + </div> |
| 55 | + </div> |
| 56 | + <span class="text-base font-semibold"> |
| 57 | + {{ t("password_reset.description") }} |
| 58 | + </span> |
| 59 | + </div> |
| 60 | + <div class="form-control"> |
| 61 | + <input |
| 62 | + v-model="v$.email.$model" |
| 63 | + type="email" |
| 64 | + name="Email" |
| 65 | + :placeholder="$t('password_reset.email')" |
| 66 | + :class="['input-bordered input', v$.email.$error && 'input-error']" |
| 67 | + /> |
| 68 | + <label class="label" v-show="v$.email.$error"> |
| 69 | + <span class="label-text-alt text-error" v-text="v$.email.$errors[0]?.$message" /> |
| 70 | + </label> |
| 71 | + </div> |
| 72 | + <div class="card-actions justify-center"> |
| 73 | + <button class="btn-primary btn" @click="() => handleSubmit()"> |
| 74 | + {{ t("password_reset.submit") }} |
| 75 | + </button> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + <div v-else class="card-body"> |
| 79 | + {{ t("password_reset.status.success") }} |
| 80 | + <div class="card-actions justify-center"> |
| 81 | + <button class="btn-primary btn" @click="() => router.push('/')"> |
| 82 | + {{ t("password_reset.return-home") }} |
| 83 | + </button> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | +</template> |
0 commit comments