snappymail/dev/View/Popup/TwoFactorTest.js

71 lines
1.4 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2014-08-25 23:49:01 +08:00
import {StorageResultType} from 'Common/Enums';
import {bMobileDevice} from 'Common/Globals';
import Remote from 'Remote/User/Ajax';
2014-08-25 15:10:51 +08:00
2016-09-10 06:38:16 +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'
})
class TwoFactorTestPopupView extends AbstractViewNext
2016-06-30 08:02:45 +08:00
{
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
2016-09-10 06:38:16 +08:00
@command((self) => '' !== self.code() && !self.testing())
testCodeCommand() {
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
this.testing(true);
Remote.testTwoFactor((result, data) => {
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
this.testing(false);
this.code.status(StorageResultType.Success === result && data && !!data.Result);
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
if (this.koTestedTrigger && this.code.status())
{
this.koTestedTrigger(true);
}
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
}, 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() {
if (!bMobileDevice)
{
this.code.focused(true);
}
2016-06-30 08:02:45 +08:00
}
}
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
export {TwoFactorTestPopupView, TwoFactorTestPopupView as default};