mirror of https://github.com/keeweb/keeweb.git
fixed sequential otp generation
This commit is contained in:
parent
c6ce694dfe
commit
5d15411d3d
|
@ -12,14 +12,45 @@ class ExternalOtpEntryModel extends ExternalEntryModel {
|
|||
if (this.otpGenerator) {
|
||||
return;
|
||||
}
|
||||
this.otpGenerator = {
|
||||
const gen = {
|
||||
next: callback => {
|
||||
this.otpState = this.device.getOtp(this, callback);
|
||||
if (gen.otp && gen.expires) {
|
||||
const timeLeft = gen.expires - Date.now();
|
||||
if (timeLeft > 0) {
|
||||
return callback(null, gen.otp, timeLeft);
|
||||
}
|
||||
}
|
||||
if (gen.promise) {
|
||||
gen.promise.then(({ err, otp, timeLeft }) => {
|
||||
callback(err, otp, timeLeft);
|
||||
});
|
||||
return;
|
||||
}
|
||||
gen.promise = new Promise(resolve => {
|
||||
gen.otpState = this.device.getOtp(this, (err, otp, timeLeft) => {
|
||||
gen.otpState = null;
|
||||
gen.promise = null;
|
||||
|
||||
if (otp && timeLeft > 0) {
|
||||
gen.otp = otp;
|
||||
gen.expires = Date.now() + timeLeft;
|
||||
} else {
|
||||
gen.otp = null;
|
||||
gen.expires = null;
|
||||
}
|
||||
|
||||
callback(err, otp, timeLeft);
|
||||
resolve({ err, otp, timeLeft });
|
||||
});
|
||||
});
|
||||
},
|
||||
cancel: () => {
|
||||
this.device.cancelGetOtp(this, this.otpState);
|
||||
if (this.otpState) {
|
||||
this.device.cancelGetOtp(this, this.otpState);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.otpGenerator = gen;
|
||||
}
|
||||
|
||||
_buildFields() {
|
||||
|
@ -31,8 +62,7 @@ class ExternalOtpEntryModel extends ExternalEntryModel {
|
|||
ExternalOtpEntryModel.defineModelProperties({
|
||||
user: undefined,
|
||||
otpGenerator: undefined,
|
||||
needsTouch: false,
|
||||
otpState: null
|
||||
needsTouch: false
|
||||
});
|
||||
|
||||
export { ExternalOtpEntryModel };
|
||||
|
|
|
@ -445,13 +445,17 @@ class DetailsView extends View {
|
|||
|
||||
initOtp() {
|
||||
this.matchingOtpEntry = null;
|
||||
if (!this.model || this.model.external) {
|
||||
|
||||
if (!this.model) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.model.external) {
|
||||
this.model.initOtpGenerator();
|
||||
return;
|
||||
}
|
||||
|
||||
this.matchingOtpEntry = this.appModel.getMatchingOtpEntry(this.model);
|
||||
|
||||
this.model.initOtpGenerator();
|
||||
this.matchingOtpEntry?.initOtpGenerator();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue