2016-08-17 06:01:20 +08:00
|
|
|
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';
|
2014-04-06 03:48:22 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
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({
|
2016-08-17 06:01:20 +08:00
|
|
|
name: 'View/Popup/TwoFactorTest',
|
|
|
|
templateID: 'PopupsTwoFactorTest'
|
|
|
|
})
|
2019-07-05 03:19:24 +08:00
|
|
|
class TwoFactorTestPopupView extends AbstractViewNext {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
|
|
|
super();
|
2014-04-06 03:48:22 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.code = ko.observable('');
|
|
|
|
this.code.focused = ko.observable(false);
|
|
|
|
this.code.status = ko.observable(null);
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.koTestedTrigger = null;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.testing = ko.observable(false);
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-07-28 23:20:14 +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());
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
clearPopup() {
|
|
|
|
this.code('');
|
|
|
|
this.code.focused(false);
|
|
|
|
this.code.status(null);
|
|
|
|
this.testing(false);
|
2015-02-16 05:55:59 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.koTestedTrigger = null;
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onShow(koTestedTrigger) {
|
|
|
|
this.clearPopup();
|
2015-02-16 05:55:59 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.koTestedTrigger = koTestedTrigger;
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onShowWithDelay() {
|
2020-09-30 18:31:34 +08:00
|
|
|
// rl.settings.app('mobile') ||
|
|
|
|
this.code.focused(true);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { TwoFactorTestPopupView, TwoFactorTestPopupView as default };
|