user kann seine AccessToken ansehen und löschen

This commit is contained in:
Tim Gröger 2020-06-05 00:35:21 +02:00
parent a25ec09b8f
commit 6caaa205ee
5 changed files with 150 additions and 11 deletions

View File

@ -162,11 +162,83 @@
append-icon
>
<template v-slot:selection="data">
<v-chip>{{data.item.name}}</v-chip>
<v-chip>{{ data.item.name }}</v-chip>
</template>
</v-combobox>
</v-col>
</v-row>
<div class="subtitle-1">
Gespeicherte Sessions
</div>
<v-card v-for="token in tokens" :key="token.id" outlined>
<v-card-text>
<v-row>
<v-col
>OS:
<v-icon>
{{
token.platform === 'macos' || token.platform === 'iphone'
? apple
: token.platform === 'windows'
? windows
: token.platfrom === 'android'
? android
: token.platform
}}
</v-icon>
<v-icon
v-if="
token.platform === 'macos' || token.platform === 'iphone'
"
>
{{ token.platform === 'macos' ? mac : iphone }}
</v-icon>
</v-col>
<v-col>
Browser:
<v-icon>
{{
token.browser === 'chrome'
? chrome
: token.browser === 'firefox'
? firefox
: token.browser === 'opera'
? opera
: token.browser === 'safari'
? safari
: token.browser
}}
</v-icon>
</v-col>
<v-col>
Letzter Aktualisierung: {{ token.timestamp.day }}.{{
token.timestamp.month
}}.{{ token.timestamp.year }} um
{{
10 > token.timestamp.hour
? '0' + String(token.timestamp.hour)
: token.timestamp.hour
}}:{{
10 > token.timestamp.minute
? '0' + String(token.timestamp.minute)
: token.timestamp.minute
}}:{{
10 > token.timestamp.second
? '0' + String(token.timestamp.second)
: token.timestamp.second
}}
</v-col>
<v-col>Lebenszeit: {{ calcLifefime(token.lifetime) }}</v-col>
<v-col>
<v-btn icon @click="deleteToken(token)">
<v-icon>
{{trashCan}}
</v-icon>
</v-btn>
</v-col>
</v-row>
</v-card-text>
</v-card>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
@ -184,13 +256,34 @@ import {
mdiAccount,
mdiGlassCocktail,
mdiCurrencyEur,
mdiFoodForkDrink
mdiFoodForkDrink,
mdiApple,
mdiGoogleChrome,
mdiFirefox,
mdiOpera,
mdiInternetExplorer,
mdiAppleSafari,
mdiLaptopMac,
mdiCellphoneIphone,
mdiTrashCan,
mdiAndroid,
mdiWindows
} from '@mdi/js'
import { mapGetters, mapActions } from 'vuex'
export default {
name: 'Config',
data() {
return {
apple: mdiApple,
mac: mdiLaptopMac,
iphone: mdiCellphoneIphone,
android: mdiAndroid,
mdiWindows: mdiWindows,
chrome: mdiGoogleChrome,
firefox: mdiFirefox,
opera: mdiOpera,
ie: mdiInternetExplorer,
safari: mdiAppleSafari,
person: mdiAccount,
bar: mdiGlassCocktail,
finanzer: mdiCurrencyEur,
@ -201,6 +294,7 @@ export default {
lastname: null,
password: null,
controlPassword: null,
trashCan: mdiTrashCan,
isFulllineText: false,
equal_password: value =>
this.password === value || 'Passwörter sind nicht identisch.',
@ -222,7 +316,9 @@ export default {
methods: {
...mapActions({
saveConfig: 'user/saveConfig',
getStatus: 'user/getStatus'
getStatus: 'user/getStatus',
getTokens: 'user/getTokens',
deleteToken: 'user/deleteToken'
}),
getWindowWidth() {
this.isFulllineText = document.documentElement.clientWidth <= 600
@ -241,6 +337,21 @@ export default {
this.saveConfig({ oldUsername: user.username, ...user })
this.password = null
this.controlPassword = null
},
calcLifefime(time) {
if (time < 60) return String(time) + 'Sekunden'
time = Math.round(time / 60)
if (time < 60) return String(time) + 'Minuten'
time = Math.round(time / 60)
if (time < 24) return String(time) + 'Stunden'
time = Math.round(time / 24)
if (time < 7) return String(time) + 'Tage'
time = Math.round(time / 7)
if (time < 30) return String(time) + 'Wochen'
time = Math.round(time / 30)
if (time < 12) return String(time) + 'Monate'
time = Math.round(time / 12)
return String(time) + 'Jahre'
}
},
computed: {
@ -248,7 +359,8 @@ export default {
user: 'user/user',
error: 'user/error',
loading: 'user/loading',
status: 'user/status'
status: 'user/status',
tokens: 'user/tokens'
}),
lock() {
return this.user.locked ? 'gesperrt' : 'nicht gesperrt'
@ -272,6 +384,7 @@ export default {
},
created() {
this.getStatus()
this.getTokens()
}
}
</script>

View File

@ -72,7 +72,8 @@ const url = {
storno: main + 'user/storno',
getAllStatus: main + 'getAllStatus',
getStatus: main + 'getStatus',
valid: main + 'valid'
valid: main + 'valid',
getAccessTokens: main + 'user/getAccessTokens'
},
barU: {
storno: main + 'bar/storno',

View File

@ -158,13 +158,11 @@ const mutations = {
: []
}
})
console.log(mop)
},
setDayLoading: (state, { getters, date, value }) => {
let day = getters.getDayToMe(date)
day.forEach(a => {
a.day.loading = value
console.log('day', value ? 'loading' : 'not loading', day, a.day.loading)
})
},
deleteJobRequestFromMe: (state, jobrequest) => {
@ -240,7 +238,6 @@ const actions = {
to_me.data,
{ headers: { Token: rootState.login.user.accessToken } }
)
console.log(to_me.data)
commit('setJobRequestsToMe', to_me.data)
workers_to_me.data.forEach(item => {
var date = new Date(

View File

@ -157,9 +157,7 @@ const actions = {
})
commit('setLifeTime', response.data.value)
var user = JSON.parse(localStorage.getItem('user'))
console.log('user',user)
user.group = response.data.group
console.log('after',user)
localStorage.setItem('user', JSON.stringify(user))
commit('updateAccessToken', user)
} catch (e) {

View File

@ -9,7 +9,8 @@ const state = {
error: '',
days: [],
messages: [],
status: []
status: [],
tokens: []
}
const mutations = {
@ -29,6 +30,10 @@ const mutations = {
state.creditList = []
state.error = ''
},
setTokens: (state, tokens) => {
state.tokens = tokens
console.log(state.tokens)
},
createAmount(creditList) {
let amount = {
type: 'Schulden',
@ -317,6 +322,28 @@ const actions = {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
async getTokens({ commit, rootState, dispatch }) {
try {
const response = await axios.get(url.user.getAccessTokens, {headers: {Token: rootState.login.user.accessToken}})
commit('setTokens', response.data)
dispatch('getLifeTime', null, { root: true })
console.log('hier bin ich')
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
async deleteToken({ commit, rootState, dispatch }, token) {
try {
const response = await axios.post(url.user.getAccessTokens, token,{headers: {Token: rootState.login.user.accessToken}})
commit('setTokens', response.data)
dispatch('getLifeTime', null, { root: true })
console.log('hier bin ich')
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
}
}
@ -349,6 +376,9 @@ const getters = {
},
status: state => {
return state.status
},
tokens: state => {
return state.tokens
}
}