fix: correctly set/change passcode

This commit is contained in:
Baptiste Grob
2020-08-26 14:51:32 +02:00
parent 696f34b788
commit a63bfd8c0a
2 changed files with 31 additions and 18 deletions

View File

@@ -17,7 +17,8 @@ import {
STRING_INVALID_IMPORT_FILE,
STRING_GENERATING_LOGIN_KEYS,
STRING_GENERATING_REGISTER_KEYS,
StringImportError
StringImportError,
STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE
} from '@/strings';
import { SyncOpStatus } from 'snjs/dist/@types/services/sync/sync_op_status';
import { PasswordWizardType } from '@/types';
@@ -52,15 +53,19 @@ type FormData = {
}
type AccountMenuState = {
formData: Partial<FormData>
appVersion: string
passcodeAutoLockOptions: any
user: any
mutable: any
importData: any
formData: Partial<FormData>;
appVersion: string;
passcodeAutoLockOptions: any;
user: any;
mutable: any;
importData: any;
encryptionStatusString: string;
server: string;
encryptionEnabled: boolean;
selectedAutoLockInterval: any;
}
class AccountMenuCtrl extends PureViewCtrl {
class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
public appVersion: string
private syncStatus?: SyncOpStatus
@@ -117,15 +122,12 @@ class AccountMenuCtrl extends PureViewCtrl {
$onInit() {
super.$onInit();
this.initProps({
closeFunction: this.closeFunction
});
this.syncStatus = this.application!.getSyncStatus();
}
close() {
this.$timeout(() => {
this.props.closeFunction();
this.closeFunction?.();
});
}
@@ -503,7 +505,7 @@ class AccountMenuCtrl extends PureViewCtrl {
});
}
submitPasscodeForm() {
async submitPasscodeForm() {
const passcode = this.getState().formData.passcode!;
if (passcode !== this.getState().formData.confirmPasscode!) {
this.application!.alertService!.alert(
@@ -511,16 +513,23 @@ class AccountMenuCtrl extends PureViewCtrl {
);
return;
}
(this.getState().formData.changingPasscode
? this.application!.changePasscode(passcode)
: this.application!.setPasscode(passcode)
).then(() => {
const onBeforeUnload = window.onbeforeunload;
try {
window.onbeforeunload = () => STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE;
if (this.application!.hasPasscode()) {
await this.application!.changePasscode(passcode);
} else {
await this.application!.setPasscode(passcode);
}
this.setFormDataState({
passcode: undefined,
confirmPasscode: undefined,
showPasscodeForm: false
});
});
} finally {
window.onbeforeunload = onBeforeUnload;
}
}
async changePasscodePressed() {

View File

@@ -58,3 +58,7 @@ export const STRING_FAILED_PASSWORD_CHANGE = "There was an error re-encrypting y
export const STRING_CONFIRM_APP_QUIT_DURING_UPGRADE =
"The encryption upgrade is in progress. You may lose data if you quit the app. " +
"Are you sure you want to quit?"
export const STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE =
"A passcode change is in progress. You may lose data if you quit the app. " +
"Are you sure you want to quit?"