Löschen und Anzeigen von Sessions
This commit is contained in:
parent
644f225428
commit
2411fc86cd
|
@ -9,7 +9,7 @@
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
const { configure } = require('quasar/wrappers');
|
const { configure } = require('quasar/wrappers');
|
||||||
|
|
||||||
module.exports = configure(function (ctx) {
|
module.exports = configure(function(ctx) {
|
||||||
return {
|
return {
|
||||||
// https://quasar.dev/quasar-cli/supporting-ts
|
// https://quasar.dev/quasar-cli/supporting-ts
|
||||||
supportTS: {
|
supportTS: {
|
||||||
|
@ -64,7 +64,7 @@ module.exports = configure(function (ctx) {
|
||||||
// extractCSS: false,
|
// extractCSS: false,
|
||||||
|
|
||||||
// https://quasar.dev/quasar-cli/handling-webpack
|
// https://quasar.dev/quasar-cli/handling-webpack
|
||||||
extendWebpack (cfg) {
|
extendWebpack(cfg) {
|
||||||
// linting is slow in TS projects, we execute it only for production builds
|
// linting is slow in TS projects, we execute it only for production builds
|
||||||
if (ctx.prod) {
|
if (ctx.prod) {
|
||||||
cfg.module.rules.push({
|
cfg.module.rules.push({
|
||||||
|
@ -103,7 +103,7 @@ module.exports = configure(function (ctx) {
|
||||||
// directives: [],
|
// directives: [],
|
||||||
|
|
||||||
// Quasar plugins
|
// Quasar plugins
|
||||||
plugins: []
|
plugins: ['LocalStorage']
|
||||||
},
|
},
|
||||||
|
|
||||||
// animations: 'all', // --- includes all animations
|
// animations: 'all', // --- includes all animations
|
||||||
|
@ -191,7 +191,7 @@ module.exports = configure(function (ctx) {
|
||||||
// More info: https://quasar.dev/quasar-cli/developing-electron-apps/node-integration
|
// More info: https://quasar.dev/quasar-cli/developing-electron-apps/node-integration
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
|
|
||||||
extendWebpack (/* cfg */) {
|
extendWebpack(/* cfg */) {
|
||||||
// do something with Electron main process Webpack cfg
|
// do something with Electron main process Webpack cfg
|
||||||
// chainWebpack also available besides this extendWebpack
|
// chainWebpack also available besides this extendWebpack
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import axios, { AxiosInstance } from 'axios';
|
import axios, { AxiosInstance } from 'axios';
|
||||||
import { boot } from 'quasar/wrappers';
|
import { boot } from 'quasar/wrappers';
|
||||||
import { StateInterface } from '../store';
|
import { Token, UserStateInterface } from 'src/plugins/user/store/user';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
|
||||||
declare module 'vue/types/vue' {
|
declare module 'vue/types/vue' {
|
||||||
|
@ -15,8 +15,10 @@ export default boot(({ Vue, store }) => {
|
||||||
axios.defaults.baseURL = config.baseURL;
|
axios.defaults.baseURL = config.baseURL;
|
||||||
|
|
||||||
axios.interceptors.request.use(config => {
|
axios.interceptors.request.use(config => {
|
||||||
const token = (<StateInterface>store.state).user.token;
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||||
|
const token: Token = (<UserStateInterface>store.state.user).token;
|
||||||
if (token) {
|
if (token) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||||
config.headers['Authorization'] = 'Token ' + token.token;
|
config.headers['Authorization'] = 'Token ' + token.token;
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
|
|
|
@ -1,20 +1,28 @@
|
||||||
import { boot } from 'quasar/wrappers';
|
import { boot } from 'quasar/wrappers';
|
||||||
import { StateInterface } from '../store';
|
import { UserStateInterface } from 'src/plugins/user/store/user';
|
||||||
|
import { RouteRecord } from 'vue-router';
|
||||||
|
|
||||||
export default boot(({ Vue, router, store }) => {
|
export default boot(({ router, store }) => {
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
let user = (<StateInterface>store.state).user;
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||||
|
const user: UserStateInterface = (<UserStateInterface>store.state).user;
|
||||||
console.log('login_boot', user);
|
console.log('login_boot', user);
|
||||||
if (
|
if (
|
||||||
to.matched.some(record => {
|
to.matched.some((record: RouteRecord) => {
|
||||||
// permissions is set AND has NO matching permission
|
// permissions is set AND has NO matching permission
|
||||||
return (
|
return (
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||||
record.meta.permissions !== undefined &&
|
record.meta.permissions !== undefined &&
|
||||||
!(
|
!(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
||||||
|
(
|
||||||
record.meta.permissions.filter((value: string) =>
|
record.meta.permissions.filter((value: string) =>
|
||||||
user.permissions.includes(value)
|
user.permissions.includes(value)
|
||||||
).length > 0
|
).length > 0
|
||||||
)
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -4,18 +4,55 @@
|
||||||
<div class="text-h5 row">
|
<div class="text-h5 row">
|
||||||
Deine Sessions:
|
Deine Sessions:
|
||||||
</div>
|
</div>
|
||||||
<!--<div class="fit row justify-center content-center items-center">
|
<div
|
||||||
|
class="fit row justify-center content-center items-center q-gutter-sm"
|
||||||
|
>
|
||||||
<q-card
|
<q-card
|
||||||
class="col-4"
|
class="col-12"
|
||||||
height=""
|
height=""
|
||||||
v-for="(session, index) in sessions"
|
v-for="(session, index) in sessions"
|
||||||
:key="'session' + index"
|
:key="'session' + index"
|
||||||
>
|
>
|
||||||
<q-card-section>
|
<q-card-section
|
||||||
{{ session }}
|
v-if="isThisSession(session.token)"
|
||||||
|
class="text-caption"
|
||||||
|
>
|
||||||
|
Diese Session.
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
<q-card-section>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-sm-6">
|
||||||
|
Browser:
|
||||||
|
<q-icon :name="getBrowserIcon(session.browser)" size="24px" />
|
||||||
|
{{ session.browser }}
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12 col-sm-6">
|
||||||
|
Plattform:
|
||||||
|
<q-icon :name="getPlatformIcon(session.platform)" size="24px" />
|
||||||
|
{{ session.platform }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-sm-6">
|
||||||
|
Lebenszeit:
|
||||||
|
{{ session.lifetime }}
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12 col-sm-6">
|
||||||
|
Läuft aus: {{ session.expires }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-actions align="right">
|
||||||
|
<q-btn
|
||||||
|
flat
|
||||||
|
round
|
||||||
|
dense
|
||||||
|
icon="mdi-delete"
|
||||||
|
@click="deleteSession(session.token)"
|
||||||
|
/>
|
||||||
|
</q-card-actions>
|
||||||
</q-card>
|
</q-card>
|
||||||
</div> -->
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<q-btn label="show sessions" @click="showRootGetters" />
|
<q-btn label="show sessions" @click="showRootGetters" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -24,19 +61,54 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { computed, defineComponent, reactive, ref } from '@vue/composition-api';
|
import { computed, defineComponent, onBeforeMount } from '@vue/composition-api';
|
||||||
import { mainLink } from '../plugin';
|
import { mainLink } from '../plugin';
|
||||||
|
import { platform } from 'os';
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
// name: 'PageName'
|
// name: 'PageName'
|
||||||
setup(_, ctx) {
|
setup(_, { root }) {
|
||||||
const sessions = computed(
|
onBeforeMount(() => {
|
||||||
() => ctx.root.$store.getters['sessions/sessions']
|
root.$store.dispatch('sessions/getSessions');
|
||||||
);
|
});
|
||||||
|
|
||||||
|
const sessions = computed(() => root.$store.getters['sessions/sessions']);
|
||||||
function showRootGetters() {
|
function showRootGetters() {
|
||||||
//ctx.root.$store.dispatch('sessions/getSessions');
|
//ctx.root.$store.dispatch('sessions/getSessions');
|
||||||
console.log(sessions.value);
|
console.log(sessions.value);
|
||||||
}
|
}
|
||||||
return { showRootGetters, sessions };
|
function getBrowserIcon(browser: string) {
|
||||||
|
return browser == 'firefox'
|
||||||
|
? 'mdi-firefox'
|
||||||
|
: browser == 'chrome'
|
||||||
|
? 'mdi-google-chrome'
|
||||||
|
: browser == 'safari'
|
||||||
|
? 'mdi-apple-safari'
|
||||||
|
: 'mdi-help';
|
||||||
|
}
|
||||||
|
function getPlatformIcon(platform: string) {
|
||||||
|
return platform == 'linux'
|
||||||
|
? 'mdi-linux'
|
||||||
|
: platform == 'windows'
|
||||||
|
? 'mdi-microsoft-windows'
|
||||||
|
: platform == 'apple'
|
||||||
|
? 'mdi-apple'
|
||||||
|
: 'mdi-help';
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteSession(token: string) {
|
||||||
|
root.$store.dispatch('sessions/deleteSession', token);
|
||||||
|
}
|
||||||
|
function isThisSession(token: string) {
|
||||||
|
return root.$store.getters['user/token'].token == token;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
showRootGetters,
|
||||||
|
sessions,
|
||||||
|
getBrowserIcon,
|
||||||
|
getPlatformIcon,
|
||||||
|
isThisSession,
|
||||||
|
deleteSession
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -40,6 +40,7 @@ const actions: ActionTree<SessionInterface, StateInterface> = {
|
||||||
headers: { Token: rootGetters['user/token'].token }
|
headers: { Token: rootGetters['user/token'].token }
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
console.log(response.data);
|
||||||
commit('setSessions', response.data);
|
commit('setSessions', response.data);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
@ -48,6 +49,22 @@ const actions: ActionTree<SessionInterface, StateInterface> = {
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
commit('setLoading', false);
|
commit('setLoading', false);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
deleteSession({ commit, dispatch, rootGetters }, token) {
|
||||||
|
commit('setLoading', true);
|
||||||
|
axios
|
||||||
|
.delete(`http://localhost:5000/auth/${token}`, {
|
||||||
|
headers: { Token: rootGetters['user/token'].token }
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
void dispatch('getSessions');
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.exception();
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
commit('setLoading', false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -81,10 +81,10 @@ const actions: ActionTree<UserStateInterface, StateInterface> = {
|
||||||
commit('setUser', response.data.user);
|
commit('setUser', response.data.user);
|
||||||
commit('setUserId', response.data.userid);
|
commit('setUserId', response.data.userid);
|
||||||
commit('showState');
|
commit('showState');
|
||||||
//LocalStorage.set('permissions', response.data.permissions);
|
LocalStorage.set('permissions', response.data.permissions);
|
||||||
//LocalStorage.set('token', response.data.token);
|
LocalStorage.set('token', response.data.token);
|
||||||
//LocalStorage.set('user', response.data.user);
|
LocalStorage.set('user', response.data.user);
|
||||||
//LocalStorage.set('userid', response.data.userid);
|
LocalStorage.set('userid', response.data.userid);
|
||||||
|
|
||||||
void Router.push({ name: 'user' });
|
void Router.push({ name: 'user' });
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue