refactor [X-05]: переделана авторизация
This commit is contained in:
1 parent
8226fb74e6
commit
c7a6eb9b00
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 { 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('/')
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<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>
|
||||
<v-img gradient="to top right, rgba(19,84,122,.8), rgba(128,208,199,.8)" />
|
||||
</template>
|
||||
@@ -13,14 +13,14 @@
|
||||
<AppNavigation />
|
||||
</v-col>
|
||||
</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>
|
||||
<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-bar> -->
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -29,7 +29,6 @@ import { useAccountStore } from '@/store/AccountStore';
|
||||
|
||||
import vcardUser from '@/components/UI/fiousercard/vcardUser.vue';
|
||||
import AppNavigation from '@/components/UI/AppHeader/AppNavigation.vue';
|
||||
import AuthForm from '@/components/UI/Auth-form.vue';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<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">
|
||||
<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}`)">
|
||||
@@ -34,7 +34,7 @@
|
||||
</v-tooltip>
|
||||
</v-list-item>
|
||||
</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-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";
|
||||
|
||||
const store = useMainmenuStore()
|
||||
const accountStore = useAccountStore()
|
||||
const accountUser = useAccountStore()
|
||||
|
||||
store.loadlinks()
|
||||
|
||||
const props = defineProps({
|
||||
isRail: Boolean,
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
<v-app>
|
||||
<AppHeader @show-side="rail = !rail" :showSideBar="rail" :logo="imageSrc"/>
|
||||
<AsideNav :asideNavigation="navigations" :isRail="rail"/>
|
||||
<v-main v-if="accountStore.cod2user" class="d-flex bg-main_theme">
|
||||
<v-main class="d-flex">
|
||||
<router-view />
|
||||
|
||||
<alert-default />
|
||||
</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-text class="justify-center bgCard h-100 ma-3 d-flex flex-column">
|
||||
<v-row class="bgText flex-grow-0">
|
||||
@@ -24,8 +23,8 @@
|
||||
</v-card>
|
||||
|
||||
<alert-default />
|
||||
</v-main>
|
||||
<v-navigation-drawer v-if="accountStore.cod2user" v-model="drawer_right" rail permanent location="right"
|
||||
</v-main> -->
|
||||
<v-navigation-drawer v-model="drawer_right" rail permanent location="right"
|
||||
@click="rail = false">
|
||||
<Online-users />
|
||||
</v-navigation-drawer>
|
||||
@@ -36,36 +35,27 @@
|
||||
import { ref, computed } from "vue";
|
||||
import { useAccountStore } from "@/store/AccountStore";
|
||||
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 { 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 AsideNav from "./AsideNav.vue";
|
||||
import alertDefault from "./alertDefault.vue"
|
||||
|
||||
export default {
|
||||
components: {
|
||||
AuthForm,
|
||||
OnlineUsers,
|
||||
CardLike,
|
||||
VcardUser,
|
||||
AdminMenu,
|
||||
AppHeader,
|
||||
AsideNav,
|
||||
alertDefault,
|
||||
},
|
||||
|
||||
setup() {
|
||||
const theme = useTheme();
|
||||
const accountStore = useAccountStore();
|
||||
const drawer_right = ref(true);
|
||||
const LikeDialog = ref(false);
|
||||
const rail = ref(false);
|
||||
const showTooltip = ref(false);
|
||||
const alert = ref(false);
|
||||
const burl = baseURL.slice(0, -1);
|
||||
const scrimg = ref([]);
|
||||
@@ -165,11 +155,6 @@ export default {
|
||||
return new URL(`@/assets/FNS-logo-xs.png`, import.meta.url).href;
|
||||
});
|
||||
|
||||
const closeinfo = () => {
|
||||
LikeDialog.value = false;
|
||||
// feedalert.value=true
|
||||
};
|
||||
|
||||
const getSafetyChapter = () => {
|
||||
axiosApiInstance.get("api/safety/gettypes/").then((response) => {
|
||||
response.data.forEach((item) => {
|
||||
@@ -198,14 +183,11 @@ export default {
|
||||
drawer_right,
|
||||
navigations,
|
||||
imageSrc,
|
||||
LikeDialog,
|
||||
scrimg,
|
||||
rail,
|
||||
showTooltip,
|
||||
alert,
|
||||
burl,
|
||||
name,
|
||||
closeinfo,
|
||||
baseURL,
|
||||
|
||||
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 { 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();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
<template>
|
||||
<v-row class="justify-center ma-0 ">
|
||||
<v-row class="justify-center ma-0 h-100">
|
||||
<v-col class="flex-column d-flex">
|
||||
|
||||
<news-crossroad />
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</v-col>
|
||||
</v-row>
|
||||
</template>
|
||||
|
||||
Reference in new issue
Block a user