From c7a6eb9b00803f5deba5de78b383920474886fde Mon Sep 17 00:00:00 2001 From: lexxik753 Date: Tue, 23 Sep 2025 13:02:40 +0300 Subject: [PATCH] =?UTF-8?q?refactor=20[X-05]:=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=B0=20=D0=B0=D0=B2=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/src/components/UI/Auth-form.vue | 7 ++-- src/front/src/layouts/default/AppHeader.vue | 7 ++-- src/front/src/layouts/default/AsideNav.vue | 8 +++-- .../src/layouts/default/DefaultPortal.vue | 32 ++++--------------- src/front/src/pages/AuthorizePage.vue | 17 ++++++++++ src/front/src/router/index.js | 26 ++++++--------- src/front/src/store/AccountStore.js | 7 ++-- src/front/src/store/MainmenuStore.js | 2 +- src/front/src/views/NewsPage.vue | 9 +----- 9 files changed, 52 insertions(+), 63 deletions(-) create mode 100644 src/front/src/pages/AuthorizePage.vue diff --git a/src/front/src/components/UI/Auth-form.vue b/src/front/src/components/UI/Auth-form.vue index b38753585..79f625aef 100644 --- a/src/front/src/components/UI/Auth-form.vue +++ b/src/front/src/components/UI/Auth-form.vue @@ -109,6 +109,7 @@ import {useAppStore} from '@/store/app' import { useVuelidate } from '@vuelidate/core' import { required, helpers } from '@vuelidate/validators' import { ref, reactive, computed, onMounted } from 'vue' +import { useRouter } from 'vue-router'; const req= helpers.withMessage('Обязательное поле', required) @@ -122,7 +123,7 @@ export default { const err = ref('') const alert = ref(false) const eyeshow = ref(false) - + const router = useRouter() const anon=reactive({ username:"9966-00-", @@ -158,7 +159,9 @@ export default { } - + finally { + router.push('/') + } } } diff --git a/src/front/src/layouts/default/AppHeader.vue b/src/front/src/layouts/default/AppHeader.vue index 866e0a7fe..d673cd4a4 100644 --- a/src/front/src/layouts/default/AppHeader.vue +++ b/src/front/src/layouts/default/AppHeader.vue @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/src/front/src/router/index.js b/src/front/src/router/index.js index 2b5408c86..4afedced2 100644 --- a/src/front/src/router/index.js +++ b/src/front/src/router/index.js @@ -1,15 +1,18 @@ -// Composables import { createRouter, createWebHistory } from "vue-router"; import { useAccountStore } from "@/store/AccountStore"; const routes = [ + { + path: "/auth", + component: () => import('@/pages/AuthorizePage.vue'), + name: "Auth", + }, { path: "/", component: () => import("@/layouts/default/DefaultPortal.vue"), meta: { - title: "Вход", + requiresAuth: true, }, - children: [ { path: "/", @@ -208,23 +211,12 @@ const router = createRouter({ routes, }); - -function isSuperuser() { - const accountStore = useAccountStore(); - - if (accountStore.user.is_superuser === false) { - return true; - } else { - return false; - } -} - router.beforeEach((to, from, next) => { - if (to.meta.requiresAuth && isSuperuser()) { + const accountStore = useAccountStore(); + if (to.meta.requiresAuth && !accountStore.cod2user) { document.title = to.meta.title; - next("/"); + next("/auth"); } else { - document.title = to.meta.title; next(); } }); diff --git a/src/front/src/store/AccountStore.js b/src/front/src/store/AccountStore.js index 9e96c19ac..39cdd0352 100644 --- a/src/front/src/store/AccountStore.js +++ b/src/front/src/store/AccountStore.js @@ -5,11 +5,12 @@ import { clearAxios, spravURL } from "@/utils/axios-api"; import VueJwtDecode from "vue-jwt-decode"; import { checkremote } from "@/utils/universal_functions"; import { useAppStore } from "@/store/app.js"; +import { useRouter } from "vue-router"; export const useAccountStore = defineStore("AccountStore", () => { const AppStore = useAppStore(); const user = ref(getuserFromStorage()); - + const router = useRouter(); @@ -62,7 +63,7 @@ export const useAccountStore = defineStore("AccountStore", () => { if (settingsStorage.value === null) { settingsUp(defaultSettings) } - + console.log(user.value); AppStore.loading = false; }; @@ -72,7 +73,7 @@ export const useAccountStore = defineStore("AccountStore", () => { user.value = {}; localStorage.removeItem("access"); localStorage.removeItem("refresh"); - + router.push('/auth') }; watch( user, diff --git a/src/front/src/store/MainmenuStore.js b/src/front/src/store/MainmenuStore.js index 2803ac238..e38d37806 100644 --- a/src/front/src/store/MainmenuStore.js +++ b/src/front/src/store/MainmenuStore.js @@ -1,5 +1,5 @@ import { defineStore } from 'pinia' -import {ref, watch} from 'vue' +import { ref } from 'vue' import { clearAxios } from '@/utils/axios-api' export const useMainmenuStore = defineStore('MainmenuStore', () => { diff --git a/src/front/src/views/NewsPage.vue b/src/front/src/views/NewsPage.vue index 94f7440a0..7f717e18a 100644 --- a/src/front/src/views/NewsPage.vue +++ b/src/front/src/views/NewsPage.vue @@ -1,14 +1,7 @@