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 @@ ...@@ -17,7 +17,6 @@
</template> </template>
<script> <script>
import LoginService from '@/api-services/login.service'
import Navbar from "./components/Navbar"; import Navbar from "./components/Navbar";
import Footer from "./components/Footer"; import Footer from "./components/Footer";
import Sidebar from "./components/Sidebar"; import Sidebar from "./components/Sidebar";
...@@ -58,11 +57,6 @@ ...@@ -58,11 +57,6 @@
} }
return res return res
}, },
logout() {
LoginService.logout(this.$store.state.token.pk)
this.$store.commit('logout')
this.$router.push('/login')
}
}, },
mounted() { 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;`); 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> <template>
<b-navbar toggleable="lg" fixed="top" :type="$sysinfo.host_oper_mode.is_prod?'light':'dark'" <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 --> <!-- Brand and toggle get grouped for better mobile display -->
<b-navbar-brand to="/"> <b-navbar-brand to="/">
<img class="d-inline-block align-top scc-img" alt="SCC" src="@/assets/img/scc_logo_small.png"/> <img class="d-inline-block align-top scc-img" alt="SCC" src="@/assets/img/scc_logo_small.png"/>
...@@ -41,7 +42,8 @@ ...@@ -41,7 +42,8 @@
</div> </div>
</b-nav-form> </b-nav-form>
<b-nav-item><span class="d-none d-xl-inline">Erweiterte </span>Suche</b-nav-item> <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']"/> <font-awesome-icon :icon="['fas', 'tasks']"/>
Geplante Aktionen Geplante Aktionen
<b-badge variant="primary">{{$store.state.ta_list ? $store.state.ta_list.length : 0}}</b-badge> <b-badge variant="primary">{{$store.state.ta_list ? $store.state.ta_list.length : 0}}</b-badge>
...@@ -58,7 +60,7 @@ ...@@ -58,7 +60,7 @@
API-Tokens API-Tokens
</b-dropdown-item> </b-dropdown-item>
<b-dropdown-divider></b-dropdown-divider> <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> </template>
</b-nav-item-dropdown> </b-nav-item-dropdown>
<b-nav-item v-else to="/login"> <b-nav-item v-else to="/login">
...@@ -72,8 +74,17 @@ ...@@ -72,8 +74,17 @@
</template> </template>
<script> <script>
import LoginService from '@/api-services/login.service'
export default { 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> </script>
......
...@@ -37,7 +37,10 @@ ...@@ -37,7 +37,10 @@
}, },
beforeRouteEnter(to, from, next) { beforeRouteEnter(to, from, next) {
next(vm => { next(vm => {
vm.prevRoute = from window.console.debug(from.path)
if(from.path != '/login') {
vm.prevRoute = from
}
}) })
}, },
methods: { methods: {
...@@ -45,8 +48,12 @@ ...@@ -45,8 +48,12 @@
ev.preventDefault() ev.preventDefault()
let self = this let self = this
LoginService.login(this.username, this.password).then((response) => { LoginService.login(this.username, this.password).then((response) => {
self.$store.commit('login', {user: response.data.login, token: response.data.token}) if(response.data.login != null) {
router.push(self.prevRoute.path) 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