mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-10 15:08:28 +03:00
Added "Enforce 2-Step verification" setting
This commit is contained in:
parent
b7709c8117
commit
acb013fbb5
47 changed files with 1271 additions and 908 deletions
314
dev/App/User.js
314
dev/App/User.js
|
|
@ -1214,6 +1214,11 @@
|
|||
});
|
||||
};
|
||||
|
||||
AppUser.prototype.bootstartTwoFactorScreen = function ()
|
||||
{
|
||||
kn.showScreenPopup(require('View/Popup/TwoFactorConfiguration'), [true]);
|
||||
};
|
||||
|
||||
AppUser.prototype.bootstartLoginScreen = function ()
|
||||
{
|
||||
Globals.$html.removeClass('rl-user-auth').addClass('rl-user-no-auth');
|
||||
|
|
@ -1221,8 +1226,6 @@
|
|||
var sCustomLoginLink = Utils.pString(Settings.settingsGet('CustomLoginLink'));
|
||||
if (!sCustomLoginLink)
|
||||
{
|
||||
kn.hideLoading();
|
||||
|
||||
kn.startScreens([
|
||||
require('Screen/User/Login')
|
||||
]);
|
||||
|
|
@ -1242,6 +1245,16 @@
|
|||
}
|
||||
};
|
||||
|
||||
AppUser.prototype.bootend = function ()
|
||||
{
|
||||
kn.hideLoading();
|
||||
|
||||
if (SimplePace)
|
||||
{
|
||||
SimplePace.set(100);
|
||||
}
|
||||
};
|
||||
|
||||
AppUser.prototype.bootstart = function ()
|
||||
{
|
||||
AbstractApp.prototype.bootstart.call(this);
|
||||
|
|
@ -1272,183 +1285,186 @@
|
|||
Events.pub('left-panel.' + (bValue ? 'off' : 'on'));
|
||||
});
|
||||
|
||||
this.setWindowTitle('');
|
||||
if (!!Settings.settingsGet('Auth'))
|
||||
{
|
||||
Globals.$html.addClass('rl-user-auth');
|
||||
|
||||
this.setWindowTitle(Translator.i18n('TITLES/LOADING'));
|
||||
if (Settings.capa(Enums.Capa.TwoFactor) &&
|
||||
Settings.capa(Enums.Capa.TwoFactorForce) &&
|
||||
Settings.settingsGet('RequireTwoFactor'))
|
||||
{
|
||||
|
||||
this.bootend();
|
||||
this.bootstartTwoFactorScreen();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setWindowTitle(Translator.i18n('TITLES/LOADING'));
|
||||
|
||||
//require.ensure([], function() { // require code splitting
|
||||
|
||||
self.foldersReload(_.bind(function (bValue) {
|
||||
self.foldersReload(_.bind(function (bValue) {
|
||||
|
||||
kn.hideLoading();
|
||||
this.bootend();
|
||||
|
||||
if (bValue)
|
||||
{
|
||||
if ($LAB && window.crypto && window.crypto.getRandomValues && Settings.capa(Enums.Capa.OpenPGP))
|
||||
if (bValue)
|
||||
{
|
||||
var fOpenpgpCallback = function (openpgp) {
|
||||
PgpStore.openpgp = openpgp;
|
||||
PgpStore.openpgpKeyring = new openpgp.Keyring();
|
||||
PgpStore.capaOpenPGP(true);
|
||||
|
||||
Events.pub('openpgp.init');
|
||||
|
||||
self.reloadOpenPgpKeys();
|
||||
};
|
||||
|
||||
if (window.openpgp)
|
||||
if ($LAB && window.crypto && window.crypto.getRandomValues && Settings.capa(Enums.Capa.OpenPGP))
|
||||
{
|
||||
fOpenpgpCallback(window.openpgp);
|
||||
var fOpenpgpCallback = function (openpgp) {
|
||||
PgpStore.openpgp = openpgp;
|
||||
PgpStore.openpgpKeyring = new openpgp.Keyring();
|
||||
PgpStore.capaOpenPGP(true);
|
||||
|
||||
Events.pub('openpgp.init');
|
||||
|
||||
self.reloadOpenPgpKeys();
|
||||
};
|
||||
|
||||
if (window.openpgp)
|
||||
{
|
||||
fOpenpgpCallback(window.openpgp);
|
||||
}
|
||||
else
|
||||
{
|
||||
$LAB.script(Links.openPgpJs()).wait(function () {
|
||||
if (window.openpgp)
|
||||
{
|
||||
fOpenpgpCallback(window.openpgp);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$LAB.script(Links.openPgpJs()).wait(function () {
|
||||
if (window.openpgp)
|
||||
PgpStore.capaOpenPGP(false);
|
||||
}
|
||||
|
||||
kn.startScreens([
|
||||
require('Screen/User/MailBox'),
|
||||
require('Screen/User/Settings'),
|
||||
require('Screen/User/About')
|
||||
]);
|
||||
|
||||
if (bGoogle || bFacebook || bTwitter)
|
||||
{
|
||||
self.socialUsers(true);
|
||||
}
|
||||
|
||||
Events.sub('interval.2m', function () {
|
||||
self.folderInformation(Cache.getFolderInboxName());
|
||||
});
|
||||
|
||||
Events.sub('interval.3m', function () {
|
||||
var sF = FolderStore.currentFolderFullNameRaw();
|
||||
if (Cache.getFolderInboxName() !== sF)
|
||||
{
|
||||
self.folderInformation(sF);
|
||||
}
|
||||
});
|
||||
|
||||
Events.sub('interval.5m-after5m', function () {
|
||||
self.folderInformationMultiply();
|
||||
});
|
||||
|
||||
Events.sub('interval.15m', function () {
|
||||
self.quota();
|
||||
});
|
||||
|
||||
Events.sub('interval.20m', function () {
|
||||
self.foldersReload();
|
||||
});
|
||||
|
||||
iContactsSyncInterval = 5 <= iContactsSyncInterval ? iContactsSyncInterval : 20;
|
||||
iContactsSyncInterval = 320 >= iContactsSyncInterval ? iContactsSyncInterval : 320;
|
||||
|
||||
_.delay(function () {
|
||||
self.contactsSync();
|
||||
}, 10000);
|
||||
|
||||
_.delay(function () {
|
||||
self.folderInformationMultiply(true);
|
||||
}, 2000);
|
||||
|
||||
window.setInterval(function () {
|
||||
self.contactsSync();
|
||||
}, iContactsSyncInterval * 60000 + 5000);
|
||||
|
||||
self.accountsAndIdentities(true);
|
||||
|
||||
_.delay(function () {
|
||||
var sF = FolderStore.currentFolderFullNameRaw();
|
||||
if (Cache.getFolderInboxName() !== sF)
|
||||
{
|
||||
self.folderInformation(sF);
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
_.delay(function () {
|
||||
self.quota();
|
||||
}, 5000);
|
||||
|
||||
_.delay(function () {
|
||||
Remote.appDelayStart(Utils.emptyFunction);
|
||||
}, 35000);
|
||||
|
||||
Events.sub('rl.auto-logout', function () {
|
||||
self.logout();
|
||||
});
|
||||
|
||||
Plugins.runHook('rl-start-user-screens');
|
||||
Events.pub('rl.bootstart-user-screens');
|
||||
|
||||
if (!!Settings.settingsGet('AccountSignMe') && window.navigator.registerProtocolHandler)
|
||||
{
|
||||
_.delay(function () {
|
||||
try {
|
||||
window.navigator.registerProtocolHandler('mailto',
|
||||
window.location.protocol + '//' + window.location.host + window.location.pathname + '?mailto&to=%s',
|
||||
'' + (Settings.settingsGet('Title') || 'RainLoop'));
|
||||
} catch(e) {}
|
||||
|
||||
if (Settings.settingsGet('MailToEmail'))
|
||||
{
|
||||
fOpenpgpCallback(window.openpgp);
|
||||
Utils.mailToHelper(Settings.settingsGet('MailToEmail'), require('View/Popup/Compose'));
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
if (!Globals.bMobileDevice)
|
||||
{
|
||||
_.defer(function () {
|
||||
self.initVerticalLayoutResizer(Enums.ClientSideKeyName.FolderListSize);
|
||||
});
|
||||
|
||||
if (Tinycon)
|
||||
{
|
||||
Tinycon.setOptions({
|
||||
fallback: false
|
||||
});
|
||||
|
||||
Events.sub('mailbox.inbox-unread-count', function (iCount) {
|
||||
Tinycon.setBubble(0 < iCount ? (99 < iCount ? 99 : iCount) : 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PgpStore.capaOpenPGP(false);
|
||||
this.bootstartLoginScreen();
|
||||
}
|
||||
|
||||
kn.startScreens([
|
||||
require('Screen/User/MailBox'),
|
||||
require('Screen/User/Settings'),
|
||||
require('Screen/User/About')
|
||||
]);
|
||||
|
||||
if (bGoogle || bFacebook || bTwitter)
|
||||
{
|
||||
self.socialUsers(true);
|
||||
}
|
||||
|
||||
Events.sub('interval.2m', function () {
|
||||
self.folderInformation(Cache.getFolderInboxName());
|
||||
});
|
||||
|
||||
Events.sub('interval.3m', function () {
|
||||
var sF = FolderStore.currentFolderFullNameRaw();
|
||||
if (Cache.getFolderInboxName() !== sF)
|
||||
{
|
||||
self.folderInformation(sF);
|
||||
}
|
||||
});
|
||||
|
||||
Events.sub('interval.5m-after5m', function () {
|
||||
self.folderInformationMultiply();
|
||||
});
|
||||
|
||||
Events.sub('interval.15m', function () {
|
||||
self.quota();
|
||||
});
|
||||
|
||||
Events.sub('interval.20m', function () {
|
||||
self.foldersReload();
|
||||
});
|
||||
|
||||
iContactsSyncInterval = 5 <= iContactsSyncInterval ? iContactsSyncInterval : 20;
|
||||
iContactsSyncInterval = 320 >= iContactsSyncInterval ? iContactsSyncInterval : 320;
|
||||
|
||||
_.delay(function () {
|
||||
self.contactsSync();
|
||||
}, 10000);
|
||||
|
||||
_.delay(function () {
|
||||
self.folderInformationMultiply(true);
|
||||
}, 2000);
|
||||
|
||||
window.setInterval(function () {
|
||||
self.contactsSync();
|
||||
}, iContactsSyncInterval * 60000 + 5000);
|
||||
|
||||
self.accountsAndIdentities(true);
|
||||
|
||||
_.delay(function () {
|
||||
var sF = FolderStore.currentFolderFullNameRaw();
|
||||
if (Cache.getFolderInboxName() !== sF)
|
||||
{
|
||||
self.folderInformation(sF);
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
_.delay(function () {
|
||||
self.quota();
|
||||
}, 5000);
|
||||
|
||||
_.delay(function () {
|
||||
Remote.appDelayStart(Utils.emptyFunction);
|
||||
}, 35000);
|
||||
|
||||
Events.sub('rl.auto-logout', function () {
|
||||
self.logout();
|
||||
});
|
||||
|
||||
Plugins.runHook('rl-start-user-screens');
|
||||
Events.pub('rl.bootstart-user-screens');
|
||||
|
||||
if (!!Settings.settingsGet('AccountSignMe') && window.navigator.registerProtocolHandler)
|
||||
{
|
||||
_.delay(function () {
|
||||
try {
|
||||
window.navigator.registerProtocolHandler('mailto',
|
||||
window.location.protocol + '//' + window.location.host + window.location.pathname + '?mailto&to=%s',
|
||||
'' + (Settings.settingsGet('Title') || 'RainLoop'));
|
||||
} catch(e) {}
|
||||
|
||||
if (Settings.settingsGet('MailToEmail'))
|
||||
{
|
||||
Utils.mailToHelper(Settings.settingsGet('MailToEmail'), require('View/Popup/Compose'));
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
if (!Globals.bMobileDevice)
|
||||
{
|
||||
_.defer(function () {
|
||||
self.initVerticalLayoutResizer(Enums.ClientSideKeyName.FolderListSize);
|
||||
});
|
||||
|
||||
if (Tinycon)
|
||||
{
|
||||
Tinycon.setOptions({
|
||||
fallback: false
|
||||
});
|
||||
|
||||
Events.sub('mailbox.inbox-unread-count', function (iCount) {
|
||||
Tinycon.setBubble(0 < iCount ? (99 < iCount ? 99 : iCount) : 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bootstartLoginScreen();
|
||||
}
|
||||
|
||||
if (SimplePace)
|
||||
{
|
||||
SimplePace.set(100);
|
||||
}
|
||||
|
||||
}, self));
|
||||
}, self));
|
||||
|
||||
//}); // require code splitting
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bootend();
|
||||
this.bootstartLoginScreen();
|
||||
|
||||
if (SimplePace)
|
||||
{
|
||||
SimplePace.set(100);
|
||||
}
|
||||
}
|
||||
|
||||
if (bGoogle)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@
|
|||
*/
|
||||
Enums.Capa = {
|
||||
'TwoFactor': 'TWO_FACTOR',
|
||||
'TwoFactorForce': 'TWO_FACTOR_FORCE',
|
||||
'OpenPGP': 'OPEN_PGP',
|
||||
'Prefetch': 'PREFETCH',
|
||||
'Gravatar': 'GRAVATAR',
|
||||
|
|
|
|||
6
dev/External/ko.js
vendored
6
dev/External/ko.js
vendored
|
|
@ -130,9 +130,15 @@
|
|||
|
||||
if (sValue)
|
||||
{
|
||||
oElement.__opentip.activate();
|
||||
oElement.__opentip.setContent(
|
||||
bi18n ? require('Common/Translator').i18n(sValue) : sValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
oElement.__opentip.setContent('');
|
||||
oElement.__opentip.deactivate();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,11 +28,27 @@
|
|||
this.weakPassword = AppAdminStore.weakPassword;
|
||||
|
||||
this.capaOpenPGP = CapaAdminStore.openPGP;
|
||||
|
||||
this.capaTwoFactorAuth = CapaAdminStore.twoFactorAuth;
|
||||
this.capaTwoFactorAuthForce = CapaAdminStore.twoFactorAuthForce;
|
||||
|
||||
this.capaTwoFactorAuth.subscribe(function (bValue) {
|
||||
if (!bValue)
|
||||
{
|
||||
this.capaTwoFactorAuthForce(false);
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.verifySslCertificate = ko.observable(!!Settings.settingsGet('VerifySslCertificate'));
|
||||
this.allowSelfSigned = ko.observable(!!Settings.settingsGet('AllowSelfSigned'));
|
||||
|
||||
this.verifySslCertificate.subscribe(function (bValue) {
|
||||
if (!bValue)
|
||||
{
|
||||
this.allowSelfSigned(true);
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.adminLogin = ko.observable(Settings.settingsGet('AdminLogin'));
|
||||
this.adminLoginError = ko.observable(false);
|
||||
this.adminPassword = ko.observable('');
|
||||
|
|
@ -126,6 +142,12 @@
|
|||
});
|
||||
});
|
||||
|
||||
this.capaTwoFactorAuthForce.subscribe(function (bValue) {
|
||||
Remote.saveAdminConfig(Utils.emptyFunction, {
|
||||
'CapaTwoFactorAuthForce': bValue ? '1' : '0'
|
||||
});
|
||||
});
|
||||
|
||||
this.useLocalProxyForExternalImages.subscribe(function (bValue) {
|
||||
Remote.saveAdminConfig(null, {
|
||||
'UseLocalProxyForExternalImages': bValue ? '1' : '0'
|
||||
|
|
|
|||
|
|
@ -39,180 +39,15 @@
|
|||
{'id': 60, 'name': Translator.i18n('SETTINGS_SECURITY/AUTOLOGIN_MINUTES_OPTION_NAME', {'MINUTES': 60})}
|
||||
];
|
||||
});
|
||||
|
||||
this.processing = ko.observable(false);
|
||||
this.clearing = ko.observable(false);
|
||||
this.secreting = ko.observable(false);
|
||||
|
||||
this.viewUser = ko.observable('');
|
||||
this.twoFactorStatus = ko.observable(false);
|
||||
|
||||
this.twoFactorTested = ko.observable(false);
|
||||
|
||||
this.viewSecret = ko.observable('');
|
||||
this.viewBackupCodes = ko.observable('');
|
||||
this.viewUrl = ko.observable('');
|
||||
|
||||
this.viewEnable_ = ko.observable(false);
|
||||
|
||||
this.viewEnable = ko.computed({
|
||||
'owner': this,
|
||||
'read': this.viewEnable_,
|
||||
'write': function (bValue) {
|
||||
|
||||
var self = this;
|
||||
|
||||
bValue = !!bValue;
|
||||
|
||||
if (bValue && this.twoFactorTested())
|
||||
{
|
||||
this.viewEnable_(bValue);
|
||||
|
||||
Remote.enableTwoFactor(function (sResult, oData) {
|
||||
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
|
||||
{
|
||||
self.viewEnable_(false);
|
||||
}
|
||||
|
||||
}, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!bValue)
|
||||
{
|
||||
this.viewEnable_(bValue);
|
||||
}
|
||||
|
||||
Remote.enableTwoFactor(function (sResult, oData) {
|
||||
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
|
||||
{
|
||||
self.viewEnable_(false);
|
||||
}
|
||||
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.viewTwoFactorEnableTooltip = ko.computed(function () {
|
||||
Translator.trigger();
|
||||
return this.twoFactorTested() || this.viewEnable_() ? '' :
|
||||
Translator.i18n('SETTINGS_SECURITY/TWO_FACTOR_SECRET_TEST_BEFORE_DESC');
|
||||
}, this);
|
||||
|
||||
this.viewTwoFactorStatus = ko.computed(function () {
|
||||
Translator.trigger();
|
||||
return Translator.i18n(
|
||||
this.twoFactorStatus() ?
|
||||
'SETTINGS_SECURITY/TWO_FACTOR_SECRET_CONFIGURED_DESC' :
|
||||
'SETTINGS_SECURITY/TWO_FACTOR_SECRET_NOT_CONFIGURED_DESC'
|
||||
);
|
||||
}, this);
|
||||
|
||||
this.twoFactorAllowedEnable = ko.computed(function () {
|
||||
return this.viewEnable() || this.twoFactorTested();
|
||||
}, this);
|
||||
|
||||
this.onResult = _.bind(this.onResult, this);
|
||||
this.onShowSecretResult = _.bind(this.onShowSecretResult, this);
|
||||
}
|
||||
|
||||
SecurityUserSettings.prototype.showSecret = function ()
|
||||
SecurityUserSettings.prototype.configureTwoFactor = function ()
|
||||
{
|
||||
this.secreting(true);
|
||||
Remote.showTwoFactorSecret(this.onShowSecretResult);
|
||||
};
|
||||
|
||||
SecurityUserSettings.prototype.hideSecret = function ()
|
||||
{
|
||||
this.viewSecret('');
|
||||
this.viewBackupCodes('');
|
||||
this.viewUrl('');
|
||||
};
|
||||
|
||||
SecurityUserSettings.prototype.createTwoFactor = function ()
|
||||
{
|
||||
this.processing(true);
|
||||
Remote.createTwoFactor(this.onResult);
|
||||
};
|
||||
|
||||
SecurityUserSettings.prototype.testTwoFactor = function ()
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/TwoFactorTest'), [this.twoFactorTested]);
|
||||
};
|
||||
|
||||
SecurityUserSettings.prototype.clearTwoFactor = function ()
|
||||
{
|
||||
this.viewSecret('');
|
||||
this.viewBackupCodes('');
|
||||
this.viewUrl('');
|
||||
|
||||
this.twoFactorTested(false);
|
||||
|
||||
this.clearing(true);
|
||||
Remote.clearTwoFactor(this.onResult);
|
||||
};
|
||||
|
||||
SecurityUserSettings.prototype.onShow = function ()
|
||||
{
|
||||
this.viewSecret('');
|
||||
this.viewBackupCodes('');
|
||||
this.viewUrl('');
|
||||
};
|
||||
|
||||
SecurityUserSettings.prototype.onResult = function (sResult, oData)
|
||||
{
|
||||
this.processing(false);
|
||||
this.clearing(false);
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
this.viewUser(Utils.pString(oData.Result.User));
|
||||
this.viewEnable_(!!oData.Result.Enable);
|
||||
this.twoFactorStatus(!!oData.Result.IsSet);
|
||||
this.twoFactorTested(!!oData.Result.Tested);
|
||||
|
||||
this.viewSecret(Utils.pString(oData.Result.Secret));
|
||||
this.viewBackupCodes(Utils.pString(oData.Result.BackupCodes).replace(/[\s]+/g, ' '));
|
||||
this.viewUrl(Utils.pString(oData.Result.Url));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.viewUser('');
|
||||
this.viewEnable_(false);
|
||||
this.twoFactorStatus(false);
|
||||
this.twoFactorTested(false);
|
||||
|
||||
this.viewSecret('');
|
||||
this.viewBackupCodes('');
|
||||
this.viewUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
SecurityUserSettings.prototype.onShowSecretResult = function (sResult, oData)
|
||||
{
|
||||
this.secreting(false);
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
this.viewSecret(Utils.pString(oData.Result.Secret));
|
||||
this.viewUrl(Utils.pString(oData.Result.Url));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.viewSecret('');
|
||||
this.viewUrl('');
|
||||
}
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/TwoFactorConfiguration'));
|
||||
};
|
||||
|
||||
SecurityUserSettings.prototype.onBuild = function ()
|
||||
{
|
||||
if (this.capaTwoFactor)
|
||||
{
|
||||
this.processing(true);
|
||||
Remote.getTwoFactor(this.onResult);
|
||||
}
|
||||
|
||||
if (this.capaAutoLogout)
|
||||
{
|
||||
var self = this;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
this.userBackground = ko.observable(false);
|
||||
this.openPGP = ko.observable(false);
|
||||
this.twoFactorAuth = ko.observable(false);
|
||||
this.twoFactorAuthForce = ko.observable(false);
|
||||
this.templates = ko.observable(false);
|
||||
}
|
||||
|
||||
|
|
@ -39,6 +40,7 @@
|
|||
this.userBackground(Settings.capa(Enums.Capa.UserBackground));
|
||||
this.openPGP(Settings.capa(Enums.Capa.OpenPGP));
|
||||
this.twoFactorAuth(Settings.capa(Enums.Capa.TwoFactor));
|
||||
this.twoFactorAuthForce(Settings.capa(Enums.Capa.TwoFactorForce));
|
||||
this.templates(Settings.capa(Enums.Capa.Templates));
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ html.rl-no-preview-pane {
|
|||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
padding: 10px 15px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.emptySubjectText {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,18 @@
|
|||
.popups {
|
||||
|
||||
.b-two-factor-content {
|
||||
|
||||
width: 750px;
|
||||
|
||||
.modal-body {
|
||||
min-height: 100px;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
background-color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.b-two-factor-test-content {
|
||||
.modal-header {
|
||||
background-color: #fff;
|
||||
|
|
|
|||
232
dev/View/Popup/TwoFactorConfiguration.js
Normal file
232
dev/View/Popup/TwoFactorConfiguration.js
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
window = require('window'),
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
|
||||
Remote = require('Remote/User/Ajax'),
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function TwoFactorConfigurationPopupView()
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsTwoFactorConfiguration');
|
||||
|
||||
this.lock = ko.observable(false);
|
||||
|
||||
this.capaTwoFactor = Settings.capa(Enums.Capa.TwoFactor);
|
||||
|
||||
this.processing = ko.observable(false);
|
||||
this.clearing = ko.observable(false);
|
||||
this.secreting = ko.observable(false);
|
||||
|
||||
this.viewUser = ko.observable('');
|
||||
this.twoFactorStatus = ko.observable(false);
|
||||
|
||||
this.twoFactorTested = ko.observable(false);
|
||||
|
||||
this.viewSecret = ko.observable('');
|
||||
this.viewBackupCodes = ko.observable('');
|
||||
this.viewUrl = ko.observable('');
|
||||
|
||||
this.viewEnable_ = ko.observable(false);
|
||||
|
||||
this.viewEnable = ko.computed({
|
||||
'owner': this,
|
||||
'read': this.viewEnable_,
|
||||
'write': function (bValue) {
|
||||
|
||||
var self = this;
|
||||
|
||||
bValue = !!bValue;
|
||||
|
||||
if (bValue && this.twoFactorTested())
|
||||
{
|
||||
this.viewEnable_(bValue);
|
||||
|
||||
Remote.enableTwoFactor(function (sResult, oData) {
|
||||
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
|
||||
{
|
||||
self.viewEnable_(false);
|
||||
}
|
||||
|
||||
}, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!bValue)
|
||||
{
|
||||
this.viewEnable_(bValue);
|
||||
}
|
||||
|
||||
Remote.enableTwoFactor(function (sResult, oData) {
|
||||
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
|
||||
{
|
||||
self.viewEnable_(false);
|
||||
}
|
||||
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.viewTwoFactorEnableTooltip = ko.computed(function () {
|
||||
Translator.trigger();
|
||||
return this.twoFactorTested() || this.viewEnable_() ? '' :
|
||||
Translator.i18n('POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_TEST_BEFORE_DESC');
|
||||
}, this);
|
||||
|
||||
this.viewTwoFactorStatus = ko.computed(function () {
|
||||
Translator.trigger();
|
||||
return Translator.i18n(
|
||||
this.twoFactorStatus() ?
|
||||
'POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_CONFIGURED_DESC' :
|
||||
'POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_NOT_CONFIGURED_DESC'
|
||||
);
|
||||
}, this);
|
||||
|
||||
this.twoFactorAllowedEnable = ko.computed(function () {
|
||||
return this.viewEnable() || this.twoFactorTested();
|
||||
}, this);
|
||||
|
||||
this.onResult = _.bind(this.onResult, this);
|
||||
this.onShowSecretResult = _.bind(this.onShowSecretResult, this);
|
||||
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/TwoFactorConfiguration', 'TwoFactorConfigurationPopupView'], TwoFactorConfigurationPopupView);
|
||||
_.extend(TwoFactorConfigurationPopupView.prototype, AbstractView.prototype);
|
||||
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.showSecret = function ()
|
||||
{
|
||||
this.secreting(true);
|
||||
Remote.showTwoFactorSecret(this.onShowSecretResult);
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.hideSecret = function ()
|
||||
{
|
||||
this.viewSecret('');
|
||||
this.viewBackupCodes('');
|
||||
this.viewUrl('');
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.createTwoFactor = function ()
|
||||
{
|
||||
this.processing(true);
|
||||
Remote.createTwoFactor(this.onResult);
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.logout = function ()
|
||||
{
|
||||
require('App/User').logout();
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.testTwoFactor = function ()
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/TwoFactorTest'), [this.twoFactorTested]);
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.clearTwoFactor = function ()
|
||||
{
|
||||
this.viewSecret('');
|
||||
this.viewBackupCodes('');
|
||||
this.viewUrl('');
|
||||
|
||||
this.twoFactorTested(false);
|
||||
|
||||
this.clearing(true);
|
||||
Remote.clearTwoFactor(this.onResult);
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.onShow = function (bLock)
|
||||
{
|
||||
this.lock(!!bLock);
|
||||
|
||||
this.viewSecret('');
|
||||
this.viewBackupCodes('');
|
||||
this.viewUrl('');
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.onHide = function ()
|
||||
{
|
||||
if (this.lock())
|
||||
{
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.onResult = function (sResult, oData)
|
||||
{
|
||||
this.processing(false);
|
||||
this.clearing(false);
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
this.viewUser(Utils.pString(oData.Result.User));
|
||||
this.viewEnable_(!!oData.Result.Enable);
|
||||
this.twoFactorStatus(!!oData.Result.IsSet);
|
||||
this.twoFactorTested(!!oData.Result.Tested);
|
||||
|
||||
this.viewSecret(Utils.pString(oData.Result.Secret));
|
||||
this.viewBackupCodes(Utils.pString(oData.Result.BackupCodes).replace(/[\s]+/g, ' '));
|
||||
this.viewUrl(Utils.pString(oData.Result.Url));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.viewUser('');
|
||||
this.viewEnable_(false);
|
||||
this.twoFactorStatus(false);
|
||||
this.twoFactorTested(false);
|
||||
|
||||
this.viewSecret('');
|
||||
this.viewBackupCodes('');
|
||||
this.viewUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.onShowSecretResult = function (sResult, oData)
|
||||
{
|
||||
this.secreting(false);
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
this.viewSecret(Utils.pString(oData.Result.Secret));
|
||||
this.viewUrl(Utils.pString(oData.Result.Url));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.viewSecret('');
|
||||
this.viewUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.onBuild = function ()
|
||||
{
|
||||
if (this.capaTwoFactor)
|
||||
{
|
||||
this.processing(true);
|
||||
Remote.getTwoFactor(this.onResult);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = TwoFactorConfigurationPopupView;
|
||||
|
||||
}());
|
||||
Loading…
Add table
Add a link
Reference in a new issue