snappymail/dev/View/Popup/TwoFactorTest.js

64 lines
1.4 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2014-08-25 23:49:01 +08:00
2019-07-05 03:19:24 +08:00
import { StorageResultType } from 'Common/Enums';
import { bMobileDevice } from 'Common/Globals';
import Remote from 'Remote/User/Fetch';
2014-08-25 15:10:51 +08:00
2019-07-05 03:19:24 +08:00
import { popup, command } from 'Knoin/Knoin';
import { AbstractViewNext } from 'Knoin/AbstractViewNext';
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
@popup({
name: 'View/Popup/TwoFactorTest',
templateID: 'PopupsTwoFactorTest'
})
2019-07-05 03:19:24 +08:00
class TwoFactorTestPopupView extends AbstractViewNext {
constructor() {
super();
this.code = ko.observable('');
this.code.focused = ko.observable(false);
this.code.status = ko.observable(null);
2014-08-25 15:10:51 +08:00
this.koTestedTrigger = null;
2014-08-21 23:08:34 +08:00
this.testing = ko.observable(false);
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.code.status(StorageResultType.Success === result && data && !!data.Result);
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
if (this.koTestedTrigger && this.code.status()) {
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.code.focused(false);
this.code.status(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() {
2019-07-05 03:19:24 +08:00
if (!bMobileDevice) {
this.code.focused(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 };