diff --git a/resources/js/components/TwofaccountShow.vue b/resources/js/components/TwofaccountShow.vue
index 6dbdf695..2071db2f 100644
--- a/resources/js/components/TwofaccountShow.vue
+++ b/resources/js/components/TwofaccountShow.vue
@@ -6,10 +6,10 @@
{{ internal_service }}
{{ internal_account }}
{{ otp }}
-
+
-
+
@@ -22,9 +22,9 @@
id: null,
internal_service: '',
internal_account: '',
- internal_icon: '',
internal_uri: '',
- internal_type: '',
+ internal_icon: '',
+ type: '',
otp : '',
timerID: null,
position: null,
@@ -32,64 +32,55 @@
}
},
- computed: {
- setService: {
- get: function () { return this.internal_service },
- set: function(value) { this.internal_service = value }
- },
- setAccount: {
- get: function () { return this.internal_account },
- set: function(value) { this.internal_account = value }
- },
- setIcon: {
- get: function () { return this.internal_icon },
- set: function(value) { this.internal_icon = value }
- },
- setUri: {
- get: function () { return this.internal_uri },
- set: function(value) { this.internal_uri = value }
- },
- setType: {
- get: function () { return this.internal_type },
- set: function(value) { this.internal_type = value }
- },
- },
-
props: {
service: '',
account: '',
uri : '',
- type: '',
+ icon: ''
},
mounted: function() {
- if( this.uri && this.type ) {
-
- this.setService = this.service
- this.setAccount = this.account
- this.setUri = this.uri
- this.setType = this.type
-
- this.internal_type === 'totp' ? this.getTOTP() : this.getHOTP()
- }
+ this.showAccount()
},
methods: {
- async getAccount(id) {
+ async showAccount(id) {
+ // 2 possible cases :
+ // - ID is provided so we fetch the account data from db but without the uri.
+ // This prevent the uri (a sensitive data) to transit via http request unnecessarily. In this
+ // case this.type is send by the backend.
+ // - an URI has been set in $parent because we need to preview some OTP before storing the account.
+ // So this.type is set on client side from the provided URI
+
this.id = id
- const { data } = await this.axios.get('api/twofaccounts/' + this.id)
+ if( this.id || this.uri ) {
+ if( this.id ) {
- this.setService = data.service
- this.setAccount = data.account
- this.setIcon = data.icon
- this.setType = data.type
+ const { data } = await this.axios.get('api/twofaccounts/' + this.id)
- this.internal_type === 'totp' ? await this.getTOTP() : await this.getHOTP()
- this.$parent.isActive = true
-
+ this.internal_service = data.service
+ this.internal_account = data.account
+ this.internal_icon = data.icon
+ this.type = data.type
+ }
+ else {
+
+ this.internal_service = this.service
+ this.internal_account = this.account
+ this.internal_icon = this.icon
+ this.internal_uri = this.uri
+ }
+
+ if( !this.type ) {
+ this.type = this.internal_uri.slice(0, 15 ) === "otpauth://totp/" ? 'totp' : 'hotp';
+ }
+
+ this.type === 'totp' ? await this.getTOTP() : await this.getHOTP()
+ this.$parent.isActive = true
+ }
},
getTOTP: function() {
@@ -135,7 +126,7 @@
getHOTP: function() {
- this.axios.get('api/twofaccounts/otp', {data: this.id ? this.id : this.internal_uri }).then(response => {
+ this.axios.post('api/twofaccounts/otp', {data: this.id ? this.id : this.internal_uri }).then(response => {
let spacePosition = Math.ceil(response.data.otp.length / 2);
this.otp = response.data.otp.substr(0, spacePosition) + " " + response.data.otp.substr(spacePosition);
@@ -146,7 +137,7 @@
clearOTP: function() {
this.stopLoop()
this.id = this.timerID = this.position = this.counter = null
- this.service = this.account = this.icon = this.type = ''
+ this.internal_service = this.internal_account = this.internal_icon = this.internal_uri = ''
this.otp = '... ...'
this.$el.querySelector('[data-is-active]').removeAttribute('data-is-active');
this.$el.querySelector('.dots li:first-child').setAttribute('data-is-active', true);
diff --git a/resources/js/langs/locales.js b/resources/js/langs/locales.js
index 80102ec6..5e760ef6 100644
--- a/resources/js/langs/locales.js
+++ b/resources/js/langs/locales.js
@@ -45,7 +45,7 @@ export default {
"refresh": "refresh",
"please": "Please ",
"response": {
- "no_valid_totp": "No valid TOTP resource in this QR code"
+ "no_valid_otp": "No valid OTP resource in this QR code"
},
"something_wrong_with_server": "Something is wrong with your server",
"Unable_to_decrypt_uri": "Unable to decrypt uri",
@@ -82,7 +82,7 @@ export default {
},
"new_account": "New account",
"edit_account": "Edit account",
- "totp_uri": "TOTP Uri",
+ "otp_uri": "OTP Uri",
"hotp_counter": "HOTP Counter",
"use_qrcode": {
"val": "Use a qrcode",
@@ -98,7 +98,8 @@ export default {
},
"choose_image": "Choose an image…",
"create": "Create",
- "save": "Save"
+ "save": "Save",
+ "test": "Test"
},
"confirm": {
"delete": "Are you sure you want to delete this account?",
@@ -220,7 +221,7 @@ export default {
"image": "Supported format are jpeg, png, bmp, gif, svg, or webp"
},
"uri": {
- "starts_with": "Only valid TOTP uri are supported"
+ "starts_with": "Only valid OTP uri are supported"
},
"email": {
"exists": "No account found using this email"
diff --git a/resources/js/views/Accounts.vue b/resources/js/views/Accounts.vue
index 3e58da9c..5e63046c 100644
--- a/resources/js/views/Accounts.vue
+++ b/resources/js/views/Accounts.vue
@@ -221,13 +221,7 @@
},
showAccount(id) {
- if( id ) {
- this.$refs.TwofaccountShow.getAccount(id)
- }
- else {
- let err = new Error("Id missing")
- this.$router.push({ name: 'genericError', params: { err: err } });
- }
+ this.$refs.TwofaccountShow.showAccount(id)
},
deleteAccount: function (id) {
diff --git a/resources/js/views/twofaccounts/Create.vue b/resources/js/views/twofaccounts/Create.vue
index b96b48e1..290dba5b 100644
--- a/resources/js/views/twofaccounts/Create.vue
+++ b/resources/js/views/twofaccounts/Create.vue
@@ -11,8 +11,7 @@
+ :uri="form.uri">
@@ -106,16 +105,29 @@
{{ $t('twofaccounts.forms.create') }}
+
+
+
+
+
+
+
+