Merge branch 'feature/accessToken' into develop

This commit is contained in:
Tim Gröger 2020-06-05 01:25:14 +02:00
commit b812b86b6a
7 changed files with 167 additions and 22 deletions

View File

@ -48,7 +48,7 @@
<v-col cols="12" sm="6"> <v-col cols="12" sm="6">
<v-text-field <v-text-field
outlined outlined
label="Password" label="neues Password"
type="password" type="password"
v-model="password" v-model="password"
/> />
@ -58,7 +58,7 @@
ref="password" ref="password"
v-model="controlPassword" v-model="controlPassword"
outlined outlined
label="Password bestätigen" label="neues Password bestätigen"
type="password" type="password"
:disabled="!password" :disabled="!password"
:rules="[equal_password]" :rules="[equal_password]"
@ -162,14 +162,87 @@
append-icon append-icon
> >
<template v-slot:selection="data"> <template v-slot:selection="data">
<v-chip>{{data.item.name}}</v-chip> <v-chip>{{ data.item.name }}</v-chip>
</template> </template>
</v-combobox> </v-combobox>
</v-col> </v-col>
</v-row> </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-text>
<v-card-actions> <v-card-actions>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-text-field outlined label="Passwort" v-model="acceptedPassword" type="password" ref="acceptedPassword" :rules="[empty_password]"></v-text-field>
<v-btn text color="primary" @click="save">Speicherns</v-btn> <v-btn text color="primary" @click="save">Speicherns</v-btn>
</v-card-actions> </v-card-actions>
<v-expand-transition> <v-expand-transition>
@ -184,13 +257,34 @@ import {
mdiAccount, mdiAccount,
mdiGlassCocktail, mdiGlassCocktail,
mdiCurrencyEur, mdiCurrencyEur,
mdiFoodForkDrink mdiFoodForkDrink,
mdiApple,
mdiGoogleChrome,
mdiFirefox,
mdiOpera,
mdiInternetExplorer,
mdiAppleSafari,
mdiLaptopMac,
mdiCellphoneIphone,
mdiTrashCan,
mdiAndroid,
mdiWindows
} from '@mdi/js' } from '@mdi/js'
import { mapGetters, mapActions } from 'vuex' import { mapGetters, mapActions } from 'vuex'
export default { export default {
name: 'Config', name: 'Config',
data() { data() {
return { return {
apple: mdiApple,
mac: mdiLaptopMac,
iphone: mdiCellphoneIphone,
android: mdiAndroid,
mdiWindows: mdiWindows,
chrome: mdiGoogleChrome,
firefox: mdiFirefox,
opera: mdiOpera,
ie: mdiInternetExplorer,
safari: mdiAppleSafari,
person: mdiAccount, person: mdiAccount,
bar: mdiGlassCocktail, bar: mdiGlassCocktail,
finanzer: mdiCurrencyEur, finanzer: mdiCurrencyEur,
@ -201,7 +295,10 @@ export default {
lastname: null, lastname: null,
password: null, password: null,
controlPassword: null, controlPassword: null,
trashCan: mdiTrashCan,
isFulllineText: false, isFulllineText: false,
acceptedPassword: null,
passError: null,
equal_password: value => equal_password: value =>
this.password === value || 'Passwörter sind nicht identisch.', this.password === value || 'Passwörter sind nicht identisch.',
email: value => { email: value => {
@ -210,7 +307,11 @@ export default {
return pattern.test(value) || 'keine gültige E-Mail' return pattern.test(value) || 'keine gültige E-Mail'
} }
return true return true
},
empty_password: () => {
return this.acceptedPassword !== null ? true : 'Password wurde nicht gesetzt'
} }
} }
}, },
mounted() { mounted() {
@ -222,7 +323,9 @@ export default {
methods: { methods: {
...mapActions({ ...mapActions({
saveConfig: 'user/saveConfig', saveConfig: 'user/saveConfig',
getStatus: 'user/getStatus' getStatus: 'user/getStatus',
getTokens: 'user/getTokens',
deleteToken: 'user/deleteToken'
}), }),
getWindowWidth() { getWindowWidth() {
this.isFulllineText = document.documentElement.clientWidth <= 600 this.isFulllineText = document.documentElement.clientWidth <= 600
@ -238,9 +341,29 @@ export default {
if (this.$refs.password.validate()) { if (this.$refs.password.validate()) {
if (this.password) user.password = this.password if (this.password) user.password = this.password
} }
this.saveConfig({ oldUsername: user.username, ...user }) if (this.$refs.acceptedPassword.validate()) {
this.saveConfig({oldUsername: user.username, ...user, acceptedPassword: this.acceptedPassword})
} else {
this.passError = "Du musst dein Password eingeben"
}
this.password = null this.password = null
this.controlPassword = null this.controlPassword = null
this.acceptedPassword = ''
},
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: { computed: {
@ -248,7 +371,8 @@ export default {
user: 'user/user', user: 'user/user',
error: 'user/error', error: 'user/error',
loading: 'user/loading', loading: 'user/loading',
status: 'user/status' status: 'user/status',
tokens: 'user/tokens'
}), }),
lock() { lock() {
return this.user.locked ? 'gesperrt' : 'nicht gesperrt' return this.user.locked ? 'gesperrt' : 'nicht gesperrt'
@ -272,6 +396,7 @@ export default {
}, },
created() { created() {
this.getStatus() this.getStatus()
this.getTokens()
} }
} }
</script> </script>

View File

@ -8,12 +8,12 @@
</v-card-title> </v-card-title>
<v-card-text> <v-card-text>
<v-expand-transition> <v-expand-transition>
<v-row align="center" justify="center" v-if="dayLoading"> <v-row align="center" justify="center" v-if="day.loading">
<v-progress-circular indeterminate color="grey" /> <v-progress-circular indeterminate color="grey" />
</v-row> </v-row>
</v-expand-transition> </v-expand-transition>
<v-expand-transition> <v-expand-transition>
<div v-show="!dayLoading"> <div v-show="!day.loading">
<div <div
v-for="(jobkinddateitem, index) in day.jobkinddate" v-for="(jobkinddateitem, index) in day.jobkinddate"
:key="index" :key="index"
@ -43,7 +43,7 @@
</div> </div>
</v-expand-transition> </v-expand-transition>
</v-card-text> </v-card-text>
<v-card-actions class="text--secondary" v-if="!dayLoading" :key="update"> <v-card-actions class="text--secondary" v-if="!day.loading" :key="update">
<v-spacer /> <v-spacer />
<v-menu <v-menu
v-model="menu" v-model="menu"
@ -94,7 +94,7 @@
v-for="(invite, index) in getInvites(day.date)" v-for="(invite, index) in getInvites(day.date)"
:key="index" :key="index"
> >
<v-chip v-on="on" style="margin: 5px"> <v-chip style="margin: 5px">
{{ invite.to_user.firstname }} {{ invite.to_user.firstname }}
{{ invite.to_user.lastname }} {{ invite.to_user.lastname }}
</v-chip> </v-chip>
@ -152,7 +152,7 @@
v-for="(request, index) in getRequests(day.date)" v-for="(request, index) in getRequests(day.date)"
:key="index" :key="index"
> >
<v-chip v-on="on" style="margin: 5px"> <v-chip style="margin: 5px">
{{ request.to_user.firstname }} {{ request.to_user.firstname }}
{{ request.to_user.lastname }} {{ request.to_user.lastname }}
</v-chip> </v-chip>
@ -344,7 +344,6 @@ export default {
return jobkinddate.job_kind return jobkinddate.job_kind
}, },
filteredDBUsersWithJobKind() { filteredDBUsersWithJobKind() {
console.log(this.day.jobkinddate)
var retVal = this.filteredDBUsers() var retVal = this.filteredDBUsers()
var job_kind = this.getJob_Kind() var job_kind = this.getJob_Kind()

View File

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

View File

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

View File

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

View File

@ -9,7 +9,8 @@ const state = {
error: '', error: '',
days: [], days: [],
messages: [], messages: [],
status: [] status: [],
tokens: []
} }
const mutations = { const mutations = {
@ -29,6 +30,9 @@ const mutations = {
state.creditList = [] state.creditList = []
state.error = '' state.error = ''
}, },
setTokens: (state, tokens) => {
state.tokens = tokens
},
createAmount(creditList) { createAmount(creditList) {
let amount = { let amount = {
type: 'Schulden', type: 'Schulden',
@ -317,6 +321,26 @@ const actions = {
if (e.response) if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true }) 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 })
} 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 })
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
} }
} }
@ -349,6 +373,9 @@ const getters = {
}, },
status: state => { status: state => {
return state.status return state.status
},
tokens: state => {
return state.tokens
} }
} }

View File

@ -79,7 +79,6 @@ const actions = {
const response = await axios.get(url.getUsers, { const response = await axios.get(url.getUsers, {
headers: { Token: rootState.login.user.accessToken } headers: { Token: rootState.login.user.accessToken }
}) })
console.log(response.data)
commit('setUsers', response.data) commit('setUsers', response.data)
commit('setUsersLoading', false) commit('setUsersLoading', false)
dispatch('getLifeTime', null, { root: true }) dispatch('getLifeTime', null, { root: true })
@ -95,7 +94,6 @@ const actions = {
const response = await axios.get(url.getUsers + '?extern=1', { const response = await axios.get(url.getUsers + '?extern=1', {
headers: { Token: rootState.login.user.accessToken } headers: { Token: rootState.login.user.accessToken }
}) })
console.log(response.data)
commit('setUsers', response.data) commit('setUsers', response.data)
commit('setUsersLoading', false) commit('setUsersLoading', false)
dispatch('getLifeTime', null, { root: true }) dispatch('getLifeTime', null, { root: true })