if not auth - redirect to login, set profile after siginin\signup
This commit is contained in:
parent
35a3eb0f56
commit
6678c6d191
|
|
@ -47,6 +47,7 @@
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onBeforeUnmount, onMounted, ref, computed } from "vue";
|
import { onBeforeUnmount, onMounted, ref, computed } from "vue";
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { onBeforeRouteUpdate } from "vue-router";
|
import { onBeforeRouteUpdate } from "vue-router";
|
||||||
import { useBreakpoint } from "vuestic-ui";
|
import { useBreakpoint } from "vuestic-ui";
|
||||||
|
|
@ -77,6 +78,10 @@ const onResize = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
const token = localStorage.getItem('token');
|
||||||
|
if (!token) {
|
||||||
|
useRouter().push({ name: "login" });
|
||||||
|
}
|
||||||
window.addEventListener("resize", onResize);
|
window.addEventListener("resize", onResize);
|
||||||
onResize();
|
onResize();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,5 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useBreakpoint } from "vuestic-ui";
|
import { useBreakpoint } from "vuestic-ui";
|
||||||
import VuesticLogo from "../components/VuesticLogo.vue";
|
import VuesticLogo from "../components/VuesticLogo.vue";
|
||||||
|
|
||||||
const breakpoint = useBreakpoint();
|
const breakpoint = useBreakpoint();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,10 @@ const submit = () => {
|
||||||
code: code.value,
|
code: code.value,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
|
||||||
localStorage.setItem('token', response.data.token);
|
localStorage.setItem('token', response.data.token);
|
||||||
|
localStorage.setItem('profile', JSON.stringify(response.data.profile));
|
||||||
|
|
||||||
router.push({ name: "dashboard" }).catch((error) => { });
|
router.push({ name: "dashboard" }).catch((error) => { });
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
if (error.response.data.detail.code_string == "ObjectNotFound") {
|
if (error.response.data.detail.code_string == "ObjectNotFound") {
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,18 @@ const submit = () => {
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
localStorage.setItem('token', response.data.token);
|
localStorage.setItem('token', response.data.token);
|
||||||
|
localStorage.setItem('profile', JSON.stringify(response.data.profile));
|
||||||
init({ message: "Вы успешно вошли!", color: "success" });
|
init({ message: "Вы успешно вошли!", color: "success" });
|
||||||
push({ name: "dashboard" });
|
push({ name: "dashboard" });
|
||||||
})
|
})
|
||||||
.catch((error) => {});
|
.catch((error) => {
|
||||||
|
|
||||||
|
init({
|
||||||
|
message: "Неверный логин или пароль",
|
||||||
|
color: "error",
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ const submit = () => {
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
localStorage.setItem('token', response.data.token);
|
localStorage.setItem('token', response.data.token);
|
||||||
|
localStorage.setItem('profile', JSON.stringify(response.data.profile));
|
||||||
init({
|
init({
|
||||||
message: "Вы успешно вошли",
|
message: "Вы успешно вошли",
|
||||||
color: "success",
|
color: "success",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<h1 class="page-title">Preferences</h1>
|
<h1 class="page-title">Настройки профиля</h1>
|
||||||
<div class="flex flex-col p-4 space-y-10 bg-backgroundSecondary rounded-lg">
|
<div class="flex flex-col p-4 space-y-10 bg-backgroundSecondary rounded-lg">
|
||||||
<div class="flex space-x-5">
|
<div class="flex space-x-5">
|
||||||
<PreferencesHeader />
|
<PreferencesHeader />
|
||||||
|
|
|
||||||
|
|
@ -43,85 +43,15 @@
|
||||||
>
|
>
|
||||||
Сбросить пароль
|
Сбросить пароль
|
||||||
</VaButton>
|
</VaButton>
|
||||||
</div>
|
</div>
|
||||||
<VaDivider />
|
<VaDivider />
|
||||||
<div
|
|
||||||
class="flex flex-col md:flex-row space-y-2 md:space-y-0 md:space-x-6 min-h-[36px] leading-5"
|
|
||||||
>
|
|
||||||
<p class="font-bold w-[200px]">Двуфакторная авторизация</p>
|
|
||||||
<div class="flex-1">
|
|
||||||
<div class="max-w-[748px]">
|
|
||||||
{{ twoFA.content }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<VaButton
|
|
||||||
:style="buttonStyles"
|
|
||||||
class="w-fit h-fit"
|
|
||||||
preset="primary"
|
|
||||||
:color="twoFA.color"
|
|
||||||
@click="toggle2FA"
|
|
||||||
>
|
|
||||||
{{ twoFA.button }}
|
|
||||||
</VaButton>
|
|
||||||
</div>
|
|
||||||
<VaDivider />
|
|
||||||
<div
|
|
||||||
class="flex flex-col md:flex-row space-y-2 md:space-y-0 md:space-x-6 min-h-[36px] leading-5"
|
|
||||||
>
|
|
||||||
<p class="font-bold w-[200px]">Email подписка</p>
|
|
||||||
<div class="flex-1">
|
|
||||||
<div class="max-w-[748px]">
|
|
||||||
<p>Чтобы управлять подписками, перейдите в</p>
|
|
||||||
<div class="flex space-x-1 w-fit">
|
|
||||||
<RouterLink
|
|
||||||
:to="{ name: 'settings' }"
|
|
||||||
class="font-semibold text-primary"
|
|
||||||
>Настройки оповещения</RouterLink
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from "vue";
|
|
||||||
|
|
||||||
import { useToast } from "vuestic-ui/web-components";
|
|
||||||
|
|
||||||
import { useUserStore } from "../../../stores/user-store";
|
import { useUserStore } from "../../../stores/user-store";
|
||||||
|
|
||||||
import { buttonStyles } from "../styles";
|
import { buttonStyles } from "../styles";
|
||||||
|
|
||||||
const store = useUserStore();
|
const store = useUserStore();
|
||||||
|
|
||||||
const { init } = useToast();
|
|
||||||
|
|
||||||
const toastMessage = computed(() =>
|
|
||||||
store.is2FAEnabled ? "2FA успешно включена" : "2FA успешно откючена",
|
|
||||||
);
|
|
||||||
|
|
||||||
const twoFA = computed(() => {
|
|
||||||
if (store.is2FAEnabled) {
|
|
||||||
return {
|
|
||||||
color: "danger",
|
|
||||||
button: "Disable 2FA",
|
|
||||||
content:
|
|
||||||
"Для вашей учетной записи теперь включена двухфакторная аутентификация (2FA), что повышает уровень безопасности при входе в систему",
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
color: "primary",
|
|
||||||
button: "Set up 2FA",
|
|
||||||
content:
|
|
||||||
"Повысьте уровень безопасности своей учетной записи. Чтобы войти в систему, вам необходимо ввести код вместе со своим именем пользователя и паролем.",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const toggle2FA = () => {
|
|
||||||
store.toggle2FA();
|
|
||||||
init({ message: toastMessage.value, color: "success" });
|
|
||||||
};
|
|
||||||
|
|
||||||
const emits = defineEmits(["openNameModal", "openResetPasswordModal"]);
|
const emits = defineEmits(["openNameModal", "openResetPasswordModal"]);
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,29 @@ import { defineStore } from "pinia";
|
||||||
|
|
||||||
export const useUserStore = defineStore("user", {
|
export const useUserStore = defineStore("user", {
|
||||||
state: () => {
|
state: () => {
|
||||||
|
if (!localStorage.getItem("profile")) {
|
||||||
|
return {
|
||||||
|
userName: "",
|
||||||
|
email: "",
|
||||||
|
memberSince: "",
|
||||||
|
pfp: "",
|
||||||
|
is2FAEnabled: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const dataUser = JSON.parse(localStorage.getItem("profile")!);
|
||||||
|
let userName = "";
|
||||||
|
if (dataUser.first_name) {
|
||||||
|
userName = dataUser.first_name;
|
||||||
|
}
|
||||||
|
if (dataUser.surname) {
|
||||||
|
if (userName.length == 0) {
|
||||||
|
userName += " ";
|
||||||
|
}
|
||||||
|
userName += dataUser.surname;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
userName: "Vasili Savitski",
|
userName: userName,
|
||||||
email: "vasili@gmail.com",
|
email: dataUser.email || "",
|
||||||
memberSince: "8/12/2020",
|
memberSince: "8/12/2020",
|
||||||
pfp: "https://picsum.photos/id/22/200/300",
|
pfp: "https://picsum.photos/id/22/200/300",
|
||||||
is2FAEnabled: false,
|
is2FAEnabled: false,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue