snappymail/dev/Settings/Admin/Security.js

125 lines
3 KiB
JavaScript
Raw Normal View History

2021-03-16 17:46:22 +08:00
import { Capa } from 'Common/Enums';
import { Settings, SettingsGet } from 'Common/Globals';
import { addObservablesTo, addSubscribablesTo } from 'Common/Utils';
import Remote from 'Remote/Admin/Fetch';
2016-07-16 05:29:42 +08:00
import { decorateKoCommands } from 'Knoin/Knoin';
2016-09-10 06:38:16 +08:00
2021-01-22 23:32:08 +08:00
export class SecurityAdminSettings {
2016-07-16 05:29:42 +08:00
constructor() {
2021-03-16 21:15:05 +08:00
this.weakPassword = rl.app.weakPassword;
2014-08-21 23:08:34 +08:00
addObservablesTo(this, {
2021-03-10 18:44:48 +08:00
useLocalProxyForExternalImages: !!SettingsGet('UseLocalProxyForExternalImages'),
2020-10-27 18:09:24 +08:00
2021-03-10 18:44:48 +08:00
verifySslCertificate: !!SettingsGet('VerifySslCertificate'),
allowSelfSigned: !!SettingsGet('AllowSelfSigned'),
2020-10-27 18:09:24 +08:00
2021-03-10 18:44:48 +08:00
adminLogin: SettingsGet('AdminLogin'),
2020-10-27 18:09:24 +08:00
adminLoginError: false,
adminPassword: '',
adminPasswordNew: '',
adminPasswordNew2: '',
adminPasswordNewError: false,
adminPasswordUpdateError: false,
2021-03-16 17:46:22 +08:00
adminPasswordUpdateSuccess: false,
2021-04-13 01:15:33 +08:00
capaOpenPGP: Settings.capa(Capa.OpenPGP)
2016-07-16 05:29:42 +08:00
});
2016-07-01 06:50:11 +08:00
addSubscribablesTo(this, {
2021-03-16 17:46:22 +08:00
adminPassword: () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
},
adminLogin: () => this.adminLoginError(false),
adminPasswordNew: () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
},
adminPasswordNew2: () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
},
capaOpenPGP: value =>
Remote.saveAdminConfig(null, {
CapaOpenPGP: value ? 1 : 0
2021-03-16 17:46:22 +08:00
}),
useLocalProxyForExternalImages: value =>
Remote.saveAdminConfig(null, {
UseLocalProxyForExternalImages: value ? 1 : 0
2021-03-16 17:46:22 +08:00
}),
verifySslCertificate: value => {
value => value || this.allowSelfSigned(true);
Remote.saveAdminConfig(null, {
VerifySslCertificate: value ? 1 : 0
2021-03-16 17:46:22 +08:00
});
},
allowSelfSigned: value =>
Remote.saveAdminConfig(null, {
AllowSelfSigned: value ? 1 : 0
2021-03-16 17:46:22 +08:00
})
2016-07-16 05:29:42 +08:00
});
2014-08-21 23:08:34 +08:00
this.onNewAdminPasswordResponse = this.onNewAdminPasswordResponse.bind(this);
decorateKoCommands(this, {
saveNewAdminPasswordCommand: self => self.adminLogin().trim() && self.adminPassword()
});
2016-09-10 06:38:16 +08:00
}
2016-07-16 05:29:42 +08:00
2016-09-10 06:38:16 +08:00
saveNewAdminPasswordCommand() {
if (!this.adminLogin().trim()) {
2016-09-10 06:38:16 +08:00
this.adminLoginError(true);
return false;
}
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
if (this.adminPasswordNew() !== this.adminPasswordNew2()) {
2016-09-10 06:38:16 +08:00
this.adminPasswordNewError(true);
return false;
}
2016-06-30 08:02:45 +08:00
2016-09-10 06:38:16 +08:00
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
2016-07-16 05:29:42 +08:00
2016-09-10 06:38:16 +08:00
Remote.saveNewAdminPassword(this.onNewAdminPasswordResponse, {
'Login': this.adminLogin(),
'Password': this.adminPassword(),
'NewPassword': this.adminPasswordNew()
});
2016-07-16 05:29:42 +08:00
2016-09-10 06:38:16 +08:00
return true;
2016-06-30 08:02:45 +08:00
}
2016-07-16 05:29:42 +08:00
onNewAdminPasswordResponse(iError, data) {
2021-03-18 21:48:21 +08:00
if (iError) {
this.adminPasswordUpdateError(true);
} else {
2016-07-16 05:29:42 +08:00
this.adminPassword('');
this.adminPasswordNew('');
this.adminPasswordNew2('');
this.adminPasswordUpdateSuccess(true);
this.weakPassword(!!data.Result.Weak);
}
2016-06-30 08:02:45 +08:00
}
2016-07-16 05:29:42 +08:00
onHide() {
this.adminPassword('');
this.adminPasswordNew('');
this.adminPasswordNew2('');
}
}