mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 13:09:21 +03:00
Revamp Issue #51 to make the whole "change password" thing a plugin
This commit is contained in:
parent
3426921c9d
commit
fb03687528
17 changed files with 207 additions and 297 deletions
|
|
@ -98,11 +98,6 @@ export const Notification = {
|
|||
AccountTwoFactorAuthRequired: 120,
|
||||
AccountTwoFactorAuthError: 121,
|
||||
|
||||
CouldNotSaveNewPassword: 130,
|
||||
CurrentPasswordIncorrect: 131,
|
||||
NewPasswordShort: 132,
|
||||
NewPasswordWeak: 133,
|
||||
|
||||
ContactsSyncError: 140,
|
||||
|
||||
CantGetMessageList: 201,
|
||||
|
|
|
|||
|
|
@ -337,6 +337,7 @@ function decorateKoCommands(thisArg, commands) {
|
|||
thisArg[key] = fn;
|
||||
});
|
||||
}
|
||||
ko.decorateCommands = decorateKoCommands;
|
||||
|
||||
/**
|
||||
* @param {miced} $items
|
||||
|
|
|
|||
|
|
@ -594,18 +594,6 @@ class RemoteUserFetch extends AbstractFetchRemote {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?Function} fCallback
|
||||
* @param {string} prevPassword
|
||||
* @param {string} newPassword
|
||||
*/
|
||||
changePassword(fCallback, prevPassword, newPassword) {
|
||||
this.defaultRequest(fCallback, 'ChangePassword', {
|
||||
'PrevPassword': prevPassword,
|
||||
'NewPassword': newPassword
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?Function} fCallback
|
||||
* @param {string} sFolderFullNameRaw
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import { TemplatesUserSettings } from 'Settings/User/Templates';
|
|||
import { FoldersUserSettings } from 'Settings/User/Folders';
|
||||
import { ThemesUserSettings } from 'Settings/User/Themes';
|
||||
import { OpenPgpUserSettings } from 'Settings/User/OpenPgp';
|
||||
import { ChangePasswordUserSettings } from 'Settings/User/ChangePassword';
|
||||
|
||||
import { SystemDropDownSettingsUserView } from 'View/User/Settings/SystemDropDown';
|
||||
import { MenuSettingsUserView } from 'View/User/Settings/Menu';
|
||||
|
|
@ -78,15 +77,6 @@ export class SettingsUserScreen extends AbstractSettingsScreen {
|
|||
);
|
||||
}
|
||||
|
||||
if (Settings.get('ChangePasswordIsAllowed')) {
|
||||
settingsAddViewModel(
|
||||
ChangePasswordUserSettings,
|
||||
'SettingsChangePassword',
|
||||
'GLOBAL/PASSWORD',
|
||||
'change-password'
|
||||
);
|
||||
}
|
||||
|
||||
if (Settings.capa(Capa.Folders)) {
|
||||
settingsAddViewModel(FoldersUserSettings, 'SettingsFolders', 'SETTINGS_LABELS/LABEL_FOLDERS_NAME', 'folders');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,90 +0,0 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { StorageResultType, Notification } from 'Common/Enums';
|
||||
import { getNotificationFromResponse, i18n } from 'Common/Translator';
|
||||
import { Settings } from 'Common/Globals';
|
||||
|
||||
import Remote from 'Remote/User/Fetch';
|
||||
|
||||
import { decorateKoCommands } from 'Knoin/Knoin';
|
||||
|
||||
export class ChangePasswordUserSettings {
|
||||
constructor() {
|
||||
ko.addObservablesTo(this, {
|
||||
changeProcess: false,
|
||||
|
||||
errorDescription: '',
|
||||
passwordMismatch: false,
|
||||
passwordUpdateError: false,
|
||||
passwordUpdateSuccess: false,
|
||||
|
||||
currentPassword: '',
|
||||
currentPasswordError: false,
|
||||
newPassword: '',
|
||||
newPassword2: '',
|
||||
});
|
||||
|
||||
this.currentPassword.subscribe(() => this.resetUpdate(true));
|
||||
this.newPassword.subscribe(() => this.resetUpdate());
|
||||
this.newPassword2.subscribe(() => this.resetUpdate());
|
||||
|
||||
decorateKoCommands(this, {
|
||||
saveNewPasswordCommand: self => !self.changeProcess()
|
||||
&& '' !== self.currentPassword()
|
||||
&& '' !== self.newPassword()
|
||||
&& '' !== self.newPassword2()
|
||||
});
|
||||
}
|
||||
|
||||
saveNewPasswordCommand() {
|
||||
if (this.newPassword() !== this.newPassword2()) {
|
||||
this.passwordMismatch(true);
|
||||
this.errorDescription(i18n('SETTINGS_CHANGE_PASSWORD/ERROR_PASSWORD_MISMATCH'));
|
||||
} else {
|
||||
this.reset(true);
|
||||
Remote.changePassword(this.onChangePasswordResponse.bind(this), this.currentPassword(), this.newPassword());
|
||||
}
|
||||
}
|
||||
|
||||
reset(change) {
|
||||
this.changeProcess(change);
|
||||
this.resetUpdate();
|
||||
this.currentPasswordError(false);
|
||||
this.errorDescription('');
|
||||
}
|
||||
|
||||
resetUpdate(current) {
|
||||
this.passwordUpdateError(false);
|
||||
this.passwordUpdateSuccess(false);
|
||||
current ? this.currentPasswordError(false) : this.passwordMismatch(false);
|
||||
}
|
||||
|
||||
onHide() {
|
||||
this.reset(false);
|
||||
this.currentPassword('');
|
||||
this.newPassword('');
|
||||
this.newPassword2('');
|
||||
}
|
||||
|
||||
onChangePasswordResponse(result, data) {
|
||||
this.reset(false);
|
||||
|
||||
if (StorageResultType.Success === result && data && data.Result) {
|
||||
this.currentPassword('');
|
||||
this.newPassword('');
|
||||
this.newPassword2('');
|
||||
|
||||
this.passwordUpdateSuccess(true);
|
||||
|
||||
rl.hash.set();
|
||||
Settings.set('AuthAccountHash', data.Result);
|
||||
} else {
|
||||
if (data && Notification.CurrentPasswordIncorrect === data.ErrorCode) {
|
||||
this.currentPasswordError(true);
|
||||
}
|
||||
|
||||
this.passwordUpdateError(true);
|
||||
this.errorDescription(getNotificationFromResponse(data, Notification.CouldNotSaveNewPassword));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue