2023-12-01 15:29:26 +01:00
|
|
|
<script setup>
|
|
|
|
import Form from '@/components/formElements/Form'
|
|
|
|
import { useUserStore } from '@/stores/user'
|
|
|
|
import { useBusStore } from '@/stores/bus'
|
|
|
|
import { useNotifyStore } from '@/stores/notify'
|
|
|
|
import { UseColorMode } from '@vueuse/components'
|
|
|
|
import { useTwofaccounts } from '@/stores/twofaccounts'
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
const user = useUserStore()
|
|
|
|
const bus = useBusStore()
|
|
|
|
const notify = useNotifyStore()
|
|
|
|
const twofaccounts = useTwofaccounts()
|
|
|
|
|
|
|
|
const qrcodeInput = ref(null)
|
|
|
|
const qrcodeInputLabel = ref(null)
|
|
|
|
const form = reactive(new Form({
|
|
|
|
qrcode: null,
|
|
|
|
inputFormat: 'fileUpload',
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upload the submitted QR code file to the backend for decoding, then route the user
|
|
|
|
* to the Create or Import form with decoded URI to prefill the form
|
|
|
|
*/
|
|
|
|
function submitQrCode() {
|
|
|
|
form.clear()
|
|
|
|
form.qrcode = qrcodeInput.value.files[0]
|
|
|
|
|
|
|
|
form.upload('/api/v1/qrcode/decode', { returnError: true }).then(response => {
|
|
|
|
if (response.data.data.slice(0, 33).toLowerCase() === "otpauth-migration://offline?data=") {
|
|
|
|
bus.migrationUri = response.data.data
|
|
|
|
router.push({ name: 'importAccounts' })
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bus.decodedUri = response.data.data
|
|
|
|
router.push({ name: 'createAccount' })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if (error.response.status !== 422) {
|
|
|
|
notify.alert({ text: error.response.data.message })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Push user to the dedicated capture view for live scan
|
|
|
|
*/
|
|
|
|
function capture() {
|
|
|
|
router.push({ name: 'capture' });
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
if( user.preferences.useDirectCapture && user.preferences.defaultCaptureMode === 'upload' ) {
|
|
|
|
qrcodeInputLabel.value.click()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2020-04-24 09:03:00 +02:00
|
|
|
<template>
|
2020-11-23 19:30:58 +01:00
|
|
|
<!-- static landing UI -->
|
|
|
|
<div class="container has-text-centered">
|
|
|
|
<div class="columns quick-uploader">
|
|
|
|
<!-- trailer phrase that invite to add an account -->
|
2023-12-01 15:29:26 +01:00
|
|
|
<div class="column is-full quick-uploader-header" :class="{ 'is-invisible' : twofaccounts.count !== 0 }">
|
2020-11-23 19:30:58 +01:00
|
|
|
{{ $t('twofaccounts.no_account_here') }}<br>
|
|
|
|
{{ $t('twofaccounts.add_first_account') }}
|
|
|
|
</div>
|
|
|
|
<!-- Livescan button -->
|
|
|
|
<div class="column is-full quick-uploader-button" >
|
|
|
|
<div class="quick-uploader-centerer">
|
|
|
|
<!-- upload a qr code (with basic file field and backend decoding) -->
|
2023-12-01 15:29:26 +01:00
|
|
|
<label role="button" tabindex="0" v-if="user.preferences.useBasicQrcodeReader" class="button is-link is-medium is-rounded is-main" ref="qrcodeInputLabel" @keyup.enter="qrcodeInputLabel.click()">
|
2022-10-12 11:30:20 +02:00
|
|
|
<input aria-hidden="true" tabindex="-1" class="file-input" type="file" accept="image/*" v-on:change="submitQrCode" ref="qrcodeInput">
|
2020-11-23 19:30:58 +01:00
|
|
|
{{ $t('twofaccounts.forms.upload_qrcode') }}
|
|
|
|
</label>
|
|
|
|
<!-- scan button that launch camera stream -->
|
2022-10-18 13:41:46 +02:00
|
|
|
<button v-else class="button is-link is-medium is-rounded is-main" @click="capture()">
|
2020-11-23 19:30:58 +01:00
|
|
|
{{ $t('twofaccounts.forms.scan_qrcode') }}
|
2022-10-12 11:30:20 +02:00
|
|
|
</button>
|
2020-04-24 09:03:00 +02:00
|
|
|
</div>
|
2023-12-01 15:29:26 +01:00
|
|
|
<FieldError v-if="form.errors.hasAny('qrcode')" :error="form.errors.get('qrcode')" :field="'qrcode'" />
|
2020-04-24 09:03:00 +02:00
|
|
|
</div>
|
2020-11-23 19:30:58 +01:00
|
|
|
<!-- alternative methods -->
|
|
|
|
<div class="column is-full">
|
2023-12-01 15:29:26 +01:00
|
|
|
<UseColorMode v-slot="{ mode }">
|
|
|
|
<div class="block" :class="mode == 'dark' ? 'has-text-light':'has-text-grey-dark'">{{ $t('twofaccounts.forms.alternative_methods') }}</div>
|
|
|
|
</UseColorMode>
|
2020-11-23 19:30:58 +01:00
|
|
|
<!-- upload a qr code -->
|
2023-12-01 15:29:26 +01:00
|
|
|
<div class="block has-text-link" v-if="!user.preferences.useBasicQrcodeReader">
|
|
|
|
<label role="button" tabindex="0" class="button is-link is-outlined is-rounded" ref="qrcodeInputLabel" @keyup.enter="qrcodeInputLabel.click()">
|
2022-10-12 11:30:20 +02:00
|
|
|
<input aria-hidden="true" tabindex="-1" class="file-input" type="file" accept="image/*" v-on:change="submitQrCode" ref="qrcodeInput">
|
2020-11-23 19:30:58 +01:00
|
|
|
{{ $t('twofaccounts.forms.upload_qrcode') }}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<!-- link to advanced form -->
|
2023-12-01 15:29:26 +01:00
|
|
|
<div class="block has-text-link">
|
|
|
|
<RouterLink class="button is-link is-outlined is-rounded" :to="{ name: 'createAccount' }" >
|
2020-11-23 19:30:58 +01:00
|
|
|
{{ $t('twofaccounts.forms.use_advanced_form') }}
|
2023-12-01 15:29:26 +01:00
|
|
|
</RouterLink>
|
2020-11-23 19:30:58 +01:00
|
|
|
</div>
|
2022-10-07 18:58:48 +02:00
|
|
|
<!-- link to import view -->
|
2023-12-01 15:29:26 +01:00
|
|
|
<div class="block has-text-link">
|
|
|
|
<RouterLink id="btnImport" class="button is-link is-outlined is-rounded" :to="{ name: 'importAccounts' }" >
|
2022-10-07 18:58:48 +02:00
|
|
|
{{ $t('twofaccounts.import.import') }}
|
2023-12-01 15:29:26 +01:00
|
|
|
</RouterLink>
|
2022-10-07 18:58:48 +02:00
|
|
|
</div>
|
2020-04-24 09:03:00 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-11-23 19:30:58 +01:00
|
|
|
<!-- Footer -->
|
2023-12-01 15:29:26 +01:00
|
|
|
<VueFooter :showButtons="true" >
|
|
|
|
<ButtonBackCloseCancel :returnTo="{ name: 'accounts' }" action="back" v-if="!twofaccounts.isEmpty" />
|
|
|
|
</VueFooter>
|
2020-04-24 09:03:00 +02:00
|
|
|
</div>
|
|
|
|
</template>
|