strava-frontend/src/pages/auth/CheckTheEmail.vue

93 lines
2.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<VaForm ref="passwordForm" @submit.prevent="submit">
<h1 class="font-semibold text-4xl mb-4">Авторизация по коду</h1>
<p class="text-base mb-4 leading-5">
Вам был выслан код, введите его и вы авторизуетесь, для смены пароля вам
необходимо зайти в настройки профиля.
</p>
<VaInput
v-model="email"
:rules="[(v: string) => !!v || 'Email обязательное поле']"
class="mb-4"
label="Введите ваш email"
type="email"
/>
<VaInput
v-model="code"
:rules="[(v: string) => !!v || 'Код обязательное поле']"
class="mb-4"
label="Введите код из письма"
type="text"
/>
<VaButton class="w-full mb-2" @click="submit">
<span v-if="!inProgress">Авторизоваться</span>
<va-progress-circle
v-else
indeterminate
size="small"
color="#a1a1a1"
></va-progress-circle
></VaButton>
</VaForm>
</template>
<script lang="ts" setup>
import { inject } from "vue";
import { ref } from "vue";
import { useForm, useToast } from "vuestic-ui";
import { useRouter, useRoute } from "vue-router";
import { AxiosResponse, AxiosInstance, AxiosError } from "axios";
const axiosAuth = inject("axiosAuth") as AxiosInstance;
const form = useForm("passwordForm");
const code = ref("");
const router = useRouter();
const email = ref(useRoute().query.email?.toString() || "");
const { init } = useToast();
const submit = () => {
if (form.validate()) {
if (inProgress.value) {
return;
}
inProgress.value = true;
axiosAuth
.post(`/api/v0/profiles/passwords/confirm/recover`, {
email: email.value,
code: code.value,
})
.then((response: AxiosResponse) => {
resetProgress();
localStorage.setItem("token", response.data.token);
localStorage.setItem("profile", JSON.stringify(response.data.profile));
localStorage.setItem("user", JSON.stringify(response.data.user));
localStorage.setItem(
"attachments",
JSON.stringify(response.data.attachments),
);
router.push({ name: "explore" }).catch(() => {});
})
.catch((error: AxiosError) => {
resetProgress();
const detail = (
error.response?.data as
{ detail?: { code_string?: string } } | undefined
)?.detail;
if (detail?.code_string === "ObjectNotFound") {
init({
message: "Неверный код",
color: "error",
});
}
});
}
};
let inProgress = ref<boolean>();
const resetProgress = () => {
inProgress.value = false;
};
</script>