2014-08-21 23:08:34 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
(function (module, require) {
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
'use strict';
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
var
|
2014-08-25 23:49:01 +08:00
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
Enums = require('Enums'),
|
|
|
|
Utils = require('Utils'),
|
|
|
|
LinkBuilder = require('LinkBuilder'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-08-27 23:59:44 +08:00
|
|
|
Settings = require('Storage:Settings'),
|
|
|
|
Data = require('Storage:Admin:Data'),
|
|
|
|
Remote = require('Storage:Admin:Remote')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function AdminSettingsSecurity()
|
|
|
|
{
|
|
|
|
this.useLocalProxyForExternalImages = Data.useLocalProxyForExternalImages;
|
|
|
|
|
2014-08-27 23:59:44 +08:00
|
|
|
this.capaOpenPGP = ko.observable(Settings.capa(Enums.Capa.OpenPGP));
|
|
|
|
this.capaTwoFactorAuth = ko.observable(Settings.capa(Enums.Capa.TwoFactor));
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-08-27 23:59:44 +08:00
|
|
|
this.adminLogin = ko.observable(Settings.settingsGet('AdminLogin'));
|
2014-08-21 23:08:34 +08:00
|
|
|
this.adminPassword = ko.observable('');
|
|
|
|
this.adminPasswordNew = ko.observable('');
|
|
|
|
this.adminPasswordNew2 = ko.observable('');
|
|
|
|
this.adminPasswordNewError = ko.observable(false);
|
|
|
|
|
|
|
|
this.adminPasswordUpdateError = ko.observable(false);
|
|
|
|
this.adminPasswordUpdateSuccess = ko.observable(false);
|
|
|
|
|
|
|
|
this.adminPassword.subscribe(function () {
|
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.adminPasswordNew.subscribe(function () {
|
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
|
|
|
this.adminPasswordNewError(false);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.adminPasswordNew2.subscribe(function () {
|
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
|
|
|
this.adminPasswordNewError(false);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.saveNewAdminPasswordCommand = Utils.createCommand(this, function () {
|
|
|
|
|
|
|
|
if (this.adminPasswordNew() !== this.adminPasswordNew2())
|
|
|
|
{
|
|
|
|
this.adminPasswordNewError(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
|
|
|
|
|
|
|
Remote.saveNewAdminPassword(this.onNewAdminPasswordResponse, {
|
|
|
|
'Password': this.adminPassword(),
|
|
|
|
'NewPassword': this.adminPasswordNew()
|
|
|
|
});
|
|
|
|
|
|
|
|
}, function () {
|
|
|
|
return '' !== this.adminPassword() && '' !== this.adminPasswordNew() && '' !== this.adminPasswordNew2();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.onNewAdminPasswordResponse = _.bind(this.onNewAdminPasswordResponse, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
AdminSettingsSecurity.prototype.onNewAdminPasswordResponse = function (sResult, oData)
|
|
|
|
{
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
|
|
|
{
|
|
|
|
this.adminPassword('');
|
|
|
|
this.adminPasswordNew('');
|
|
|
|
this.adminPasswordNew2('');
|
|
|
|
|
|
|
|
this.adminPasswordUpdateSuccess(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.adminPasswordUpdateError(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
AdminSettingsSecurity.prototype.onBuild = function ()
|
|
|
|
{
|
2014-08-25 15:10:51 +08:00
|
|
|
var
|
2014-08-27 23:59:44 +08:00
|
|
|
Remote = require('Storage:Admin:Remote')
|
2014-08-25 15:10:51 +08:00
|
|
|
;
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.capaOpenPGP.subscribe(function (bValue) {
|
|
|
|
Remote.saveAdminConfig(Utils.emptyFunction, {
|
|
|
|
'CapaOpenPGP': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.capaTwoFactorAuth.subscribe(function (bValue) {
|
|
|
|
Remote.saveAdminConfig(Utils.emptyFunction, {
|
|
|
|
'CapaTwoFactorAuth': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.useLocalProxyForExternalImages.subscribe(function (bValue) {
|
|
|
|
Remote.saveAdminConfig(null, {
|
|
|
|
'UseLocalProxyForExternalImages': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
AdminSettingsSecurity.prototype.onHide = function ()
|
|
|
|
{
|
|
|
|
this.adminPassword('');
|
|
|
|
this.adminPasswordNew('');
|
|
|
|
this.adminPasswordNew2('');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
AdminSettingsSecurity.prototype.phpInfoLink = function ()
|
|
|
|
{
|
|
|
|
return LinkBuilder.phpInfo();
|
|
|
|
};
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
module.exports = AdminSettingsSecurity;
|
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
}(module, require));
|