refactor [X-05]: переделана авторизация
This commit is contained in:
1 parent
ead1cf90cc
commit
6edbb4459c
9 files changed
+52
-63
No files matched your search
@@ -109,6 +109,7 @@ import {useAppStore} from '@/store/app'
|
|||||||
import { useVuelidate } from '@vuelidate/core'
|
import { useVuelidate } from '@vuelidate/core'
|
||||||
import { required, helpers } from '@vuelidate/validators'
|
import { required, helpers } from '@vuelidate/validators'
|
||||||
import { ref, reactive, computed, onMounted } from 'vue'
|
import { ref, reactive, computed, onMounted } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
const req= helpers.withMessage('Обязательное поле', required)
|
const req= helpers.withMessage('Обязательное поле', required)
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ export default {
|
|||||||
const err = ref('')
|
const err = ref('')
|
||||||
const alert = ref(false)
|
const alert = ref(false)
|
||||||
const eyeshow = ref(false)
|
const eyeshow = ref(false)
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
const anon=reactive({
|
const anon=reactive({
|
||||||
username:"9966-00-",
|
username:"9966-00-",
|
||||||
@@ -158,7 +159,9 @@ export default {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
router.push('/')
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-app-bar v-if="accountStore.cod2user" density="compact" color="teal-darken-4" elevation="1">
|
<v-app-bar density="compact" color="teal-darken-4" elevation="1">
|
||||||
<template v-slot:image>
|
<template v-slot:image>
|
||||||
<v-img gradient="to top right, rgba(19,84,122,.8), rgba(128,208,199,.8)" />
|
<v-img gradient="to top right, rgba(19,84,122,.8), rgba(128,208,199,.8)" />
|
||||||
</template>
|
</template>
|
||||||
@@ -13,14 +13,14 @@
|
|||||||
<AppNavigation />
|
<AppNavigation />
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-app-bar>
|
</v-app-bar>
|
||||||
<v-app-bar v-else density="compact" color="teal-darken-4" elevation="1">
|
<!-- <v-app-bar v-else density="compact" color="teal-darken-4" elevation="1">
|
||||||
<template v-slot:image>
|
<template v-slot:image>
|
||||||
<v-img gradient="to top right, rgba(19,84,122,.8), rgba(128,208,199,.8)" />
|
<v-img gradient="to top right, rgba(19,84,122,.8), rgba(128,208,199,.8)" />
|
||||||
</template>
|
</template>
|
||||||
<v-col class="d-flex justify-end">
|
<v-col class="d-flex justify-end">
|
||||||
<AuthForm @challengealert="alarm= true"/>
|
<AuthForm @challengealert="alarm= true"/>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-app-bar>
|
</v-app-bar> -->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@@ -29,7 +29,6 @@ import { useAccountStore } from '@/store/AccountStore';
|
|||||||
|
|
||||||
import vcardUser from '@/components/UI/fiousercard/vcardUser.vue';
|
import vcardUser from '@/components/UI/fiousercard/vcardUser.vue';
|
||||||
import AppNavigation from '@/components/UI/AppHeader/AppNavigation.vue';
|
import AppNavigation from '@/components/UI/AppHeader/AppNavigation.vue';
|
||||||
import AuthForm from '@/components/UI/Auth-form.vue';
|
|
||||||
|
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-navigation-drawer v-if="accountStore.cod2user" :rail="props.isRail" permanent class="text-body-2">
|
<v-navigation-drawer :rail="props.isRail" permanent class="text-body-2">
|
||||||
<div class="d-flex flex-column h-100">
|
<div class="d-flex flex-column h-100">
|
||||||
<v-list v-for="(nav, index) in props.asideNavigation" :key="index" density="compact" nav>
|
<v-list v-for="(nav, index) in props.asideNavigation" :key="index" density="compact" nav>
|
||||||
<v-list-item v-if="!('submenu' in nav)" :prepend-icon="nav.ico" @click="router.push(`${nav.path}`)">
|
<v-list-item v-if="!('submenu' in nav)" :prepend-icon="nav.ico" @click="router.push(`${nav.path}`)">
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
</v-tooltip>
|
</v-tooltip>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</v-list>
|
</v-list>
|
||||||
<v-list class="text-blue-grey-lighten-1" nav>
|
<v-list v-if="accountUser.user.is_staff" class="text-blue-grey-lighten-1" nav>
|
||||||
<v-list-item prepend-icon="mdi-wrench" title="Панель администратора" :href="baseURL + 'admin'" target="_blank" link>
|
<v-list-item prepend-icon="mdi-wrench" title="Панель администратора" :href="baseURL + 'admin'" target="_blank" link>
|
||||||
<v-tooltip v-if="props.isRail" location="top" activator="parent">
|
<v-tooltip v-if="props.isRail" location="top" activator="parent">
|
||||||
Панель администратора
|
Панель администратора
|
||||||
@@ -55,7 +55,9 @@ import { baseURL } from '@/utils/axios-api';
|
|||||||
import pageCounter from "@/components/UI/defaultportal/page-counter.vue";
|
import pageCounter from "@/components/UI/defaultportal/page-counter.vue";
|
||||||
|
|
||||||
const store = useMainmenuStore()
|
const store = useMainmenuStore()
|
||||||
const accountStore = useAccountStore()
|
const accountUser = useAccountStore()
|
||||||
|
|
||||||
|
store.loadlinks()
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
isRail: Boolean,
|
isRail: Boolean,
|
||||||
|
|||||||
@@ -2,12 +2,11 @@
|
|||||||
<v-app>
|
<v-app>
|
||||||
<AppHeader @show-side="rail = !rail" :showSideBar="rail" :logo="imageSrc"/>
|
<AppHeader @show-side="rail = !rail" :showSideBar="rail" :logo="imageSrc"/>
|
||||||
<AsideNav :asideNavigation="navigations" :isRail="rail"/>
|
<AsideNav :asideNavigation="navigations" :isRail="rail"/>
|
||||||
<v-main v-if="accountStore.cod2user" class="d-flex bg-main_theme">
|
<v-main class="d-flex">
|
||||||
<router-view />
|
<router-view />
|
||||||
|
|
||||||
<alert-default />
|
<alert-default />
|
||||||
</v-main>
|
</v-main>
|
||||||
<v-main v-else class="d-flex align-center text-h3 bg-teal-lighten-2">
|
<!-- <v-main v-else class="d-flex align-center text-h3 bg-teal-lighten-2">
|
||||||
<v-card class="h-100 w-100 d-flex justify-center rounded-0 flex-column" :image="`${burl}${scrimg}`">
|
<v-card class="h-100 w-100 d-flex justify-center rounded-0 flex-column" :image="`${burl}${scrimg}`">
|
||||||
<v-card-text class="justify-center bgCard h-100 ma-3 d-flex flex-column">
|
<v-card-text class="justify-center bgCard h-100 ma-3 d-flex flex-column">
|
||||||
<v-row class="bgText flex-grow-0">
|
<v-row class="bgText flex-grow-0">
|
||||||
@@ -24,8 +23,8 @@
|
|||||||
</v-card>
|
</v-card>
|
||||||
|
|
||||||
<alert-default />
|
<alert-default />
|
||||||
</v-main>
|
</v-main> -->
|
||||||
<v-navigation-drawer v-if="accountStore.cod2user" v-model="drawer_right" rail permanent location="right"
|
<v-navigation-drawer v-model="drawer_right" rail permanent location="right"
|
||||||
@click="rail = false">
|
@click="rail = false">
|
||||||
<Online-users />
|
<Online-users />
|
||||||
</v-navigation-drawer>
|
</v-navigation-drawer>
|
||||||
@@ -36,36 +35,27 @@
|
|||||||
import { ref, computed } from "vue";
|
import { ref, computed } from "vue";
|
||||||
import { useAccountStore } from "@/store/AccountStore";
|
import { useAccountStore } from "@/store/AccountStore";
|
||||||
import { useTheme } from "vuetify";
|
import { useTheme } from "vuetify";
|
||||||
import AuthForm from "@/components/UI/Auth-form.vue";
|
|
||||||
import OnlineUsers from "@/components/UI/fiousercard/onlineUsers.vue";
|
|
||||||
import CardLike from "@/components/cardLike.vue";
|
|
||||||
import { axiosApiInstance, clearAxios } from "@/utils/axios-api";
|
import { axiosApiInstance, clearAxios } from "@/utils/axios-api";
|
||||||
|
|
||||||
import { baseURL } from "@/utils/axios-api";
|
import { baseURL } from "@/utils/axios-api";
|
||||||
import VcardUser from "@/components/UI/fiousercard/vcardUser.vue";
|
|
||||||
import AdminMenu from "@/layouts/default/AdminMenu.vue";
|
|
||||||
|
|
||||||
|
import OnlineUsers from "@/components/UI/fiousercard/onlineUsers.vue";
|
||||||
import AppHeader from "./AppHeader.vue";
|
import AppHeader from "./AppHeader.vue";
|
||||||
import AsideNav from "./AsideNav.vue";
|
import AsideNav from "./AsideNav.vue";
|
||||||
|
import alertDefault from "./alertDefault.vue"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
AuthForm,
|
|
||||||
OnlineUsers,
|
OnlineUsers,
|
||||||
CardLike,
|
|
||||||
VcardUser,
|
|
||||||
AdminMenu,
|
|
||||||
AppHeader,
|
AppHeader,
|
||||||
AsideNav,
|
AsideNav,
|
||||||
|
alertDefault,
|
||||||
},
|
},
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const accountStore = useAccountStore();
|
const accountStore = useAccountStore();
|
||||||
const drawer_right = ref(true);
|
const drawer_right = ref(true);
|
||||||
const LikeDialog = ref(false);
|
|
||||||
const rail = ref(false);
|
const rail = ref(false);
|
||||||
const showTooltip = ref(false);
|
|
||||||
const alert = ref(false);
|
const alert = ref(false);
|
||||||
const burl = baseURL.slice(0, -1);
|
const burl = baseURL.slice(0, -1);
|
||||||
const scrimg = ref([]);
|
const scrimg = ref([]);
|
||||||
@@ -165,11 +155,6 @@ export default {
|
|||||||
return new URL(`@/assets/FNS-logo-xs.png`, import.meta.url).href;
|
return new URL(`@/assets/FNS-logo-xs.png`, import.meta.url).href;
|
||||||
});
|
});
|
||||||
|
|
||||||
const closeinfo = () => {
|
|
||||||
LikeDialog.value = false;
|
|
||||||
// feedalert.value=true
|
|
||||||
};
|
|
||||||
|
|
||||||
const getSafetyChapter = () => {
|
const getSafetyChapter = () => {
|
||||||
axiosApiInstance.get("api/safety/gettypes/").then((response) => {
|
axiosApiInstance.get("api/safety/gettypes/").then((response) => {
|
||||||
response.data.forEach((item) => {
|
response.data.forEach((item) => {
|
||||||
@@ -198,14 +183,11 @@ export default {
|
|||||||
drawer_right,
|
drawer_right,
|
||||||
navigations,
|
navigations,
|
||||||
imageSrc,
|
imageSrc,
|
||||||
LikeDialog,
|
|
||||||
scrimg,
|
scrimg,
|
||||||
rail,
|
rail,
|
||||||
showTooltip,
|
|
||||||
alert,
|
alert,
|
||||||
burl,
|
burl,
|
||||||
name,
|
name,
|
||||||
closeinfo,
|
|
||||||
baseURL,
|
baseURL,
|
||||||
|
|
||||||
message,
|
message,
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<template>
|
||||||
|
<v-app>
|
||||||
|
<v-app-bar density="compact" color="teal-darken-4" elevation="1">
|
||||||
|
<template v-slot:image>
|
||||||
|
<v-img gradient="to top right, rgba(19,84,122,.8), rgba(128,208,199,.8)" />
|
||||||
|
</template>
|
||||||
|
<v-col class="d-flex justify-end">
|
||||||
|
<AuthForm @challengealert="alarm= true"/>
|
||||||
|
</v-col>
|
||||||
|
</v-app-bar>
|
||||||
|
</v-app>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import AuthForm from "@/components/UI/Auth-form.vue"
|
||||||
|
|
||||||
|
</script>
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
// Composables
|
|
||||||
import { createRouter, createWebHistory } from "vue-router";
|
import { createRouter, createWebHistory } from "vue-router";
|
||||||
import { useAccountStore } from "@/store/AccountStore";
|
import { useAccountStore } from "@/store/AccountStore";
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
|
{
|
||||||
|
path: "/auth",
|
||||||
|
component: () => import('@/pages/AuthorizePage.vue'),
|
||||||
|
name: "Auth",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
component: () => import("@/layouts/default/DefaultPortal.vue"),
|
component: () => import("@/layouts/default/DefaultPortal.vue"),
|
||||||
meta: {
|
meta: {
|
||||||
title: "Вход",
|
requiresAuth: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
@@ -208,23 +211,12 @@ const router = createRouter({
|
|||||||
routes,
|
routes,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function isSuperuser() {
|
|
||||||
const accountStore = useAccountStore();
|
|
||||||
|
|
||||||
if (accountStore.user.is_superuser === false) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
if (to.meta.requiresAuth && isSuperuser()) {
|
const accountStore = useAccountStore();
|
||||||
|
if (to.meta.requiresAuth && !accountStore.cod2user) {
|
||||||
document.title = to.meta.title;
|
document.title = to.meta.title;
|
||||||
next("/");
|
next("/auth");
|
||||||
} else {
|
} else {
|
||||||
document.title = to.meta.title;
|
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import { clearAxios, spravURL } from "@/utils/axios-api";
|
|||||||
import VueJwtDecode from "vue-jwt-decode";
|
import VueJwtDecode from "vue-jwt-decode";
|
||||||
import { checkremote } from "@/utils/universal_functions";
|
import { checkremote } from "@/utils/universal_functions";
|
||||||
import { useAppStore } from "@/store/app.js";
|
import { useAppStore } from "@/store/app.js";
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
|
|
||||||
export const useAccountStore = defineStore("AccountStore", () => {
|
export const useAccountStore = defineStore("AccountStore", () => {
|
||||||
const AppStore = useAppStore();
|
const AppStore = useAppStore();
|
||||||
const user = ref(getuserFromStorage());
|
const user = ref(getuserFromStorage());
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ export const useAccountStore = defineStore("AccountStore", () => {
|
|||||||
if (settingsStorage.value === null) {
|
if (settingsStorage.value === null) {
|
||||||
settingsUp(defaultSettings)
|
settingsUp(defaultSettings)
|
||||||
}
|
}
|
||||||
|
console.log(user.value);
|
||||||
AppStore.loading = false;
|
AppStore.loading = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ export const useAccountStore = defineStore("AccountStore", () => {
|
|||||||
user.value = {};
|
user.value = {};
|
||||||
localStorage.removeItem("access");
|
localStorage.removeItem("access");
|
||||||
localStorage.removeItem("refresh");
|
localStorage.removeItem("refresh");
|
||||||
|
router.push('/auth')
|
||||||
};
|
};
|
||||||
watch(
|
watch(
|
||||||
user,
|
user,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import {ref, watch} from 'vue'
|
import { ref } from 'vue'
|
||||||
import { clearAxios } from '@/utils/axios-api'
|
import { clearAxios } from '@/utils/axios-api'
|
||||||
|
|
||||||
export const useMainmenuStore = defineStore('MainmenuStore', () => {
|
export const useMainmenuStore = defineStore('MainmenuStore', () => {
|
||||||
|
|||||||
@@ -1,14 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-row class="justify-center ma-0 ">
|
<v-row class="justify-center ma-0 h-100">
|
||||||
<v-col class="flex-column d-flex">
|
<v-col class="flex-column d-flex">
|
||||||
|
|
||||||
<news-crossroad />
|
<news-crossroad />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in new issue
Block a user