snappymail/dev/View/Popup/TwoFactorTest.js

57 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-07-05 03:19:24 +08:00
import { StorageResultType } from 'Common/Enums';
import Remote from 'Remote/User/Fetch';
2014-08-25 15:10:51 +08:00
import { command } from 'Knoin/Knoin';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
class TwoFactorTestPopupView extends AbstractViewPopup {
constructor() {
super('TwoFactorTest');
this.addObservables({
code: '',
codeFocused: false,
codeStatus: null,
2014-08-25 15:10:51 +08:00
testing: false
});
2014-08-21 23:08:34 +08:00
this.koTestedTrigger = null;
2016-09-10 06:38:16 +08:00
}
2014-08-21 23:08:34 +08:00
@command((self) => self.code() && !self.testing())
2016-09-10 06:38:16 +08:00
testCodeCommand() {
this.testing(true);
Remote.testTwoFactor((result, data) => {
this.testing(false);
this.codeStatus(StorageResultType.Success === result && data && !!data.Result);
2014-08-21 23:08:34 +08:00
if (this.koTestedTrigger && this.codeStatus()) {
2016-09-10 06:38:16 +08:00
this.koTestedTrigger(true);
}
}, this.code());
}
2014-08-21 23:08:34 +08:00
clearPopup() {
this.code('');
this.codeFocused(false);
this.codeStatus(null);
this.testing(false);
2015-02-16 05:55:59 +08:00
this.koTestedTrigger = null;
}
2014-08-21 23:08:34 +08:00
onShow(koTestedTrigger) {
this.clearPopup();
2015-02-16 05:55:59 +08:00
this.koTestedTrigger = koTestedTrigger;
}
2014-08-21 23:08:34 +08:00
onShowWithDelay() {
this.codeFocused(true);
2016-06-30 08:02:45 +08:00
}
}
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
export { TwoFactorTestPopupView, TwoFactorTestPopupView as default };