OTP updates without API call
This commit is contained in:
parent
08a4882eaa
commit
52a3f852fe
@ -12,11 +12,11 @@
|
|||||||
<span
|
<span
|
||||||
class="otp"
|
class="otp"
|
||||||
@click="copyOtp"
|
@click="copyOtp"
|
||||||
@mouseenter="otpHidden = false"
|
@mouseenter="otpShown = true"
|
||||||
@mouseleave="otpHidden = true"
|
@mouseleave="otpShown = showOtp === 'yes' ? true : false"
|
||||||
>
|
>
|
||||||
<span v-if="otpHidden">******</span>
|
<span v-if="otpShown">{{ this.otp }}</span>
|
||||||
<span v-else>{{ generateTotp(secret) }}</span>
|
<span v-else>******</span>
|
||||||
</span>
|
</span>
|
||||||
<button class="edit-button" @click="copyOtp">
|
<button class="edit-button" @click="copyOtp">
|
||||||
<img src="../assets/copy-icon.png" class="button-icon" />
|
<img src="../assets/copy-icon.png" class="button-icon" />
|
||||||
@ -33,25 +33,26 @@ export default {
|
|||||||
issuer: String,
|
issuer: String,
|
||||||
username: String,
|
username: String,
|
||||||
secret: String,
|
secret: String,
|
||||||
hideOtps: Boolean,
|
showOtp: {
|
||||||
|
type: String,
|
||||||
|
default: "no",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
otp: 123456,
|
otp: 123456,
|
||||||
notes: "",
|
notes: "",
|
||||||
otpHidden: true,
|
otpShown: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
generateTotp(secret) {
|
generateTotp() {
|
||||||
const { otp, expires } = TOTP.generate(secret);
|
const { otp, expires } = TOTP.generate(this.secret);
|
||||||
const remaining = (expires - Date.now()) / 30000;
|
const now = new Date();
|
||||||
this.remainingTime = remaining / 1000;
|
const remainingTime = expires - now;
|
||||||
this.timerWidth = remaining * 100;
|
|
||||||
// console.log("hello");
|
|
||||||
this.otp = otp;
|
this.otp = otp;
|
||||||
return otp;
|
setTimeout(this.generateTotp, remainingTime);
|
||||||
},
|
},
|
||||||
|
|
||||||
async copyOtp() {
|
async copyOtp() {
|
||||||
@ -71,9 +72,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.hideOtps) {
|
this.otpShown = this.showOtp === "yes" ? true : false;
|
||||||
this.otpHidden = !this.hideOtps;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {},
|
created() {},
|
||||||
|
Loading…
Reference in New Issue
Block a user