mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-08-19 01:46:03 +02:00
Add user option to automatically copy OTP on display - Close #125
This commit is contained in:
@@ -143,30 +143,50 @@
|
||||
getOtp: async function() {
|
||||
|
||||
try {
|
||||
let request, password
|
||||
|
||||
if(this.internal_id) {
|
||||
const { data } = await this.axios.get('/api/v1/twofaccounts/' + this.internal_id + '/otp')
|
||||
return data
|
||||
request = {
|
||||
method: 'get',
|
||||
url: '/api/v1/twofaccounts/' + this.internal_id + '/otp'
|
||||
}
|
||||
}
|
||||
else if(this.internal_uri) {
|
||||
const { data } = await this.axios.post('/api/v1/twofaccounts/otp', {
|
||||
uri: this.internal_uri
|
||||
})
|
||||
return data
|
||||
request = {
|
||||
method: 'post',
|
||||
url: '/api/v1/twofaccounts/otp',
|
||||
data: {
|
||||
uri: this.internal_uri
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const { data } = await this.axios.post('/api/v1/twofaccounts/otp', {
|
||||
service : this.internal_service,
|
||||
account : this.internal_account,
|
||||
icon : this.internal_icon,
|
||||
otp_type : this.internal_otp_type,
|
||||
secret : this.internal_secret,
|
||||
digits : this.internal_digits,
|
||||
algorithm : this.internal_algorithm,
|
||||
period : this.internal_period,
|
||||
counter : this.internal_counter,
|
||||
})
|
||||
return data
|
||||
request = {
|
||||
method: 'post',
|
||||
url: '/api/v1/twofaccounts/otp',
|
||||
data: {
|
||||
service : this.internal_service,
|
||||
account : this.internal_account,
|
||||
icon : this.internal_icon,
|
||||
otp_type : this.internal_otp_type,
|
||||
secret : this.internal_secret,
|
||||
digits : this.internal_digits,
|
||||
algorithm : this.internal_algorithm,
|
||||
period : this.internal_period,
|
||||
counter : this.internal_counter,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await this.axios(request).then(response => {
|
||||
if(this.$root.appSettings.copyOtpOnDisplay) {
|
||||
this.copyAndNotify(response.data.password)
|
||||
}
|
||||
password = response.data
|
||||
})
|
||||
|
||||
return password
|
||||
|
||||
}
|
||||
catch(error) {
|
||||
if (error.response.status === 422) {
|
||||
@@ -182,6 +202,7 @@
|
||||
|
||||
this.internal_password = otp.password
|
||||
this.internal_otp_type = otp.otp_type
|
||||
|
||||
let generated_at = otp.generated_at
|
||||
let period = otp.period
|
||||
|
||||
@@ -314,7 +335,18 @@
|
||||
|
||||
clipboardErrorHandler ({ value, event }) {
|
||||
console.log('error', value)
|
||||
}
|
||||
},
|
||||
|
||||
copyAndNotify (strToCopy) {
|
||||
// see https://web.dev/async-clipboard/ for futur Clipboard API usage.
|
||||
// The API should allow to copy the password on each trip without user interaction.
|
||||
|
||||
// For now too many browsers don't support the clipboard-write permission
|
||||
// (see https://developer.mozilla.org/en-US/docs/Web/API/Permissions#browser_support)
|
||||
|
||||
this.$clipboard(strToCopy)
|
||||
this.$notify({ type: 'is-success', text: this.$t('commons.copied_to_clipboard') })
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
|
@@ -32,6 +32,9 @@
|
||||
<form-checkbox v-on:showOtpAsDot="saveSetting('showOtpAsDot', $event)" :form="form" fieldName="showOtpAsDot" :label="$t('settings.forms.show_otp_as_dot.label')" :help="$t('settings.forms.show_otp_as_dot.help')" />
|
||||
<!-- close otp on copy -->
|
||||
<form-checkbox v-on:closeOtpOnCopy="saveSetting('closeOtpOnCopy', $event)" :form="form" fieldName="closeOtpOnCopy" :label="$t('settings.forms.close_otp_on_copy.label')" :help="$t('settings.forms.close_otp_on_copy.help')" />
|
||||
<!-- copy otp on get -->
|
||||
<form-checkbox v-on:copyOtpOnDisplay="saveSetting('copyOtpOnDisplay', $event)" :form="form" fieldName="copyOtpOnDisplay" :label="$t('settings.forms.copy_otp_on_display.label')" :help="$t('settings.forms.copy_otp_on_display.help')" />
|
||||
|
||||
|
||||
<h4 class="title is-4 pt-4 has-text-grey-light">{{ $t('settings.data_input') }}</h4>
|
||||
<!-- basic qrcode -->
|
||||
@@ -81,6 +84,7 @@
|
||||
lang: 'browser',
|
||||
showOtpAsDot: null,
|
||||
closeOtpOnCopy: null,
|
||||
copyOtpOnDisplay: null,
|
||||
useBasicQrcodeReader: null,
|
||||
showAccountsIcons: null,
|
||||
displayMode: '',
|
||||
|
Reference in New Issue
Block a user