Commit d7abbf66 authored by janis.streib's avatar janis.streib 🦉
Browse files

FIX: login/logout handling

parent 604a6604
Pipeline #92707 passed with stages
in 7 minutes and 44 seconds
......@@ -17,7 +17,6 @@
</template>
<script>
import LoginService from '@/api-services/login.service'
import Navbar from "./components/Navbar";
import Footer from "./components/Footer";
import Sidebar from "./components/Sidebar";
......@@ -58,11 +57,6 @@
}
return res
},
logout() {
LoginService.logout(this.$store.state.token.pk)
this.$store.commit('logout')
this.$router.push('/login')
}
},
mounted() {
window.console.log('%c ', `font-size:0px; padding: 200px; background:url(${window.location.protocol}//${window.location.hostname}:${window.location.port}/important.webp) no-repeat; background-position: center; background-size: contain;`);
......
<template>
<b-navbar toggleable="lg" fixed="top" :type="$sysinfo.host_oper_mode.is_prod?'light':'dark'"
:variant="$sysinfo.host_oper_mode.is_prod?'light':'dark'" :class="`bg-${$sysinfo.host_oper_mode.mode}` + ' shadow'">
:variant="$sysinfo.host_oper_mode.is_prod?'light':'dark'"
:class="`bg-${$sysinfo.host_oper_mode.mode}` + ' shadow'">
<!-- Brand and toggle get grouped for better mobile display -->
<b-navbar-brand to="/">
<img class="d-inline-block align-top scc-img" alt="SCC" src="@/assets/img/scc_logo_small.png"/>
......@@ -41,7 +42,8 @@
</div>
</b-nav-form>
<b-nav-item><span class="d-none d-xl-inline">Erweiterte </span>Suche</b-nav-item>
<b-nav-item :active="$store.state.show_sidebar" @click="$store.commit('showSidebar', !$store.state.show_sidebar)">
<b-nav-item :active="$store.state.show_sidebar"
@click="$store.commit('showSidebar', !$store.state.show_sidebar)">
<font-awesome-icon :icon="['fas', 'tasks']"/>
Geplante Aktionen
<b-badge variant="primary">{{$store.state.ta_list ? $store.state.ta_list.length : 0}}</b-badge>
......@@ -58,7 +60,7 @@
API-Tokens
</b-dropdown-item>
<b-dropdown-divider></b-dropdown-divider>
<b-dropdown-item @click="$store.commit('logout')">Abmelden</b-dropdown-item>
<b-dropdown-item @click="logout">Abmelden</b-dropdown-item>
</template>
</b-nav-item-dropdown>
<b-nav-item v-else to="/login">
......@@ -72,8 +74,17 @@
</template>
<script>
import LoginService from '@/api-services/login.service'
export default {
name: "Navbar"
name: "Navbar",
methods: {
async logout() {
await LoginService.logout(this.$store.state.token.pk)
this.$store.commit('logout')
await this.$router.push('/login')
}
}
}
</script>
......
......@@ -37,7 +37,10 @@
},
beforeRouteEnter(to, from, next) {
next(vm => {
vm.prevRoute = from
window.console.debug(from.path)
if(from.path != '/login') {
vm.prevRoute = from
}
})
},
methods: {
......@@ -45,8 +48,12 @@
ev.preventDefault()
let self = this
LoginService.login(this.username, this.password).then((response) => {
self.$store.commit('login', {user: response.data.login, token: response.data.token})
router.push(self.prevRoute.path)
if(response.data.login != null) {
self.$store.commit('login', {user: response.data.login, token: response.data.token})
router.push(self.prevRoute.path)
} else {
// TODO: invalid login
}
})
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment