mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-28 11:13:11 +01:00
142 lines
5.5 KiB
Vue
142 lines
5.5 KiB
Vue
<template>
|
|
<div class="section">
|
|
<div class="columns is-mobile is-centered">
|
|
<div class="column is-two-thirds-tablet is-half-desktop is-one-third-widescreen is-one-quarter-fullhd">
|
|
<h1 class="title">Edit account</h1>
|
|
<form @submit.prevent="updateAccount">
|
|
<div class="field">
|
|
<label class="label">Service</label>
|
|
<div class="control">
|
|
<input class="input" type="text" placeholder="example.com" v-model="twofaccount.service" required autofocus />
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label class="label">Account</label>
|
|
<div class="control">
|
|
<input class="input" type="text" placeholder="John DOE" v-model="twofaccount.account" />
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label class="label">Icon</label>
|
|
<div class="file is-dark">
|
|
<label class="file-label">
|
|
<input class="file-input" type="file" accept="image/*" v-on:change="uploadIcon" ref="iconInput">
|
|
<span class="file-cta">
|
|
<span class="file-icon">
|
|
<font-awesome-icon :icon="['fas', 'image']" />
|
|
</span>
|
|
<span class="file-label">Choose an image…</span>
|
|
</span>
|
|
</label>
|
|
<span class="tag is-black is-large" v-if="twofaccount.icon.length > 0">
|
|
<img class="icon-preview" :src="twofaccount.icon" >
|
|
<button class="delete is-small" @click="deleteIcon"></button>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div class="field is-grouped">
|
|
<div class="control">
|
|
<button type="submit" class="button is-link">Save</button>
|
|
</div>
|
|
<div class="control">
|
|
<router-link :to="{ name: 'accounts', params: { InitialEditMode: true } }" class="button is-text">Cancel</router-link>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
twofaccount: {
|
|
'service' : '',
|
|
'account' : '',
|
|
'uri' : '',
|
|
'icon' : ''
|
|
}
|
|
}
|
|
},
|
|
|
|
created: function(){
|
|
this.getAccount();
|
|
},
|
|
|
|
methods: {
|
|
getAccount: function () {
|
|
let token = localStorage.getItem('jwt')
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
|
|
|
axios.get('/api/twofaccounts/' + this.$route.params.twofaccountId).then(response => {
|
|
this.twofaccount = response.data
|
|
})
|
|
},
|
|
|
|
updateAccount: function() {
|
|
let token = localStorage.getItem('jwt')
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
|
|
|
axios.put('/api/twofaccounts/' + this.$route.params.twofaccountId, this.twofaccount).then(response => {
|
|
this.$router.push({name: 'accounts', params: { InitialEditMode: true }});
|
|
})
|
|
},
|
|
|
|
uploadIcon(event) {
|
|
|
|
let token = localStorage.getItem('jwt')
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
|
|
|
let files = this.$refs.iconInput.files
|
|
|
|
if (!files.length) {
|
|
return false;
|
|
}
|
|
|
|
// clean possible already uploaded icon
|
|
if( this.twofaccount.icon ) {
|
|
this.deleteIcon()
|
|
}
|
|
|
|
let imgdata = new FormData();
|
|
|
|
imgdata.append('icon', files[0]);
|
|
|
|
let config = {
|
|
header : {
|
|
'Content-Type' : 'multipart/form-data',
|
|
}
|
|
}
|
|
|
|
axios.post('/api/icon/upload', imgdata, config).then(response => {
|
|
console.log('icon path > ', response);
|
|
this.twofaccount.icon = response.data;
|
|
}
|
|
)
|
|
},
|
|
|
|
deleteIcon(event) {
|
|
|
|
let token = localStorage.getItem('jwt')
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
|
|
|
axios.delete('/api/icon/delete/' + this.twofaccount.icon.replace('storage/', '')).then(response => {
|
|
this.twofaccount.icon = ''
|
|
}
|
|
)
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
</script> |