2FAuth/resources/js/views/Create.vue

174 lines
7.4 KiB
Vue
Raw Normal View History

<template>
2020-01-02 00:09:19 +01:00
<div class="modal modal-otp is-active">
<div class="modal-background"></div>
<div class="modal-content">
<section class="section">
<div class="columns is-centered">
<div class="column is-three-quarters">
<div class="box has-background-black-ter ">
<form @submit.prevent="createAccount">
2020-01-02 12:57:50 +01:00
<h1 class="subtitle is-2">New account</h1>
2020-01-03 17:25:56 +01:00
<div class="field">
2020-01-05 21:07:49 +01:00
<div class="file is-dark is-boxed">
<label class="file-label">
2020-01-05 23:21:28 +01:00
<input class="file-input" type="file" accept="image/*" v-on:change="uploadQrcode" ref="qrcodeInput">
2020-01-05 21:07:49 +01:00
<span class="file-cta">
<span class="file-icon">
2020-01-05 23:21:28 +01:00
<font-awesome-icon :icon="['fas', 'qrcode']" size="lg" />
2020-01-05 21:07:49 +01:00
</span>
<span class="file-label">Upload a qrcode</span>
2020-01-03 17:25:56 +01:00
</span>
2020-01-05 21:07:49 +01:00
</label>
</div>
2020-01-03 17:25:56 +01:00
</div>
2020-01-02 00:09:19 +01:00
<div class="field">
2020-01-02 12:57:50 +01:00
<label class="label">Service</label>
2020-01-02 00:09:19 +01:00
<div class="control">
<input class="input" type="text" placeholder="Name" v-model="twofaccount.name" required autofocus />
</div>
</div>
2020-01-02 00:09:19 +01:00
<div class="field">
<label class="label">Email</label>
<div class="control">
2020-01-03 17:25:56 +01:00
<input class="input" type="text" placeholder="Email" v-model="twofaccount.email" />
2020-01-02 00:09:19 +01:00
</div>
</div>
2020-01-02 00:09:19 +01:00
<div class="field">
<label class="label">Uri</label>
<div class="control">
2020-01-03 17:25:56 +01:00
<input class="input" type="text" placeholder="Uri" v-model="twofaccount.uri" />
2020-01-02 00:09:19 +01:00
</div>
</div>
2020-01-02 00:09:19 +01:00
<div class="field">
<label class="label">Icon</label>
2020-01-05 23:21:28 +01:00
<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>
</div>
</div>
<div class="field">
2020-01-02 00:09:19 +01:00
<div class="control">
2020-01-03 17:25:56 +01:00
<input class="input" type="text" placeholder="Icon" v-model="twofaccount.icon" />
2020-01-02 00:09:19 +01:00
</div>
</div>
2020-01-02 00:09:19 +01:00
<div class="field is-grouped">
<div class="control">
<router-link :to="{ name: 'accounts' }" class="button is-light">Cancel</router-link>
</div>
<div class="control">
2020-01-02 12:57:50 +01:00
<button type="submit" class="button is-link">Create</button>
2020-01-02 00:09:19 +01:00
</div>
</div>
2020-01-02 00:09:19 +01:00
</form>
</div>
</div>
</div>
2020-01-02 00:09:19 +01:00
</section>
</div>
</div>
</template>
<script>
export default {
data() {
return {
2020-01-05 23:21:28 +01:00
twofaccount: {
'name' : '',
'email' : '',
'uri' : '',
'icon' : ''
}
}
},
methods: {
createAccount: function() {
let token = localStorage.getItem('jwt')
axios.defaults.headers.common['Content-Type'] = 'application/json'
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
axios.post('/api/twofaccounts', this.twofaccount).then(response => {
this.$router.push({name: 'accounts'});
})
2020-01-03 17:25:56 +01:00
},
uploadQrcode(event) {
let token = localStorage.getItem('jwt')
axios.defaults.headers.common['Content-Type'] = 'application/json'
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
2020-01-05 23:21:28 +01:00
let files = this.$refs.qrcodeInput.files
2020-01-03 17:25:56 +01:00
if (!files.length) {
console.log('no files');
return false;
}
else {
console.log(files.length + ' file(s) found');
}
let imgdata = new FormData();
imgdata.append('qrcode', files[0]);
let config = {
header : {
'Content-Type' : 'multipart/form-data',
}
}
axios.post('/api/qrcode/decode', imgdata, config).then(response => {
console.log('image upload response > ', response);
this.twofaccount = response.data;
}
)
2020-01-05 23:21:28 +01:00
},
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) {
console.log('no files');
return false;
}
else {
console.log(files.length + ' file(s) found');
}
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;
}
)
}
},
}
</script>