fix: correctly set/change passcode
This commit is contained in:
@@ -17,7 +17,8 @@ import {
|
|||||||
STRING_INVALID_IMPORT_FILE,
|
STRING_INVALID_IMPORT_FILE,
|
||||||
STRING_GENERATING_LOGIN_KEYS,
|
STRING_GENERATING_LOGIN_KEYS,
|
||||||
STRING_GENERATING_REGISTER_KEYS,
|
STRING_GENERATING_REGISTER_KEYS,
|
||||||
StringImportError
|
StringImportError,
|
||||||
|
STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE
|
||||||
} from '@/strings';
|
} from '@/strings';
|
||||||
import { SyncOpStatus } from 'snjs/dist/@types/services/sync/sync_op_status';
|
import { SyncOpStatus } from 'snjs/dist/@types/services/sync/sync_op_status';
|
||||||
import { PasswordWizardType } from '@/types';
|
import { PasswordWizardType } from '@/types';
|
||||||
@@ -52,15 +53,19 @@ type FormData = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AccountMenuState = {
|
type AccountMenuState = {
|
||||||
formData: Partial<FormData>
|
formData: Partial<FormData>;
|
||||||
appVersion: string
|
appVersion: string;
|
||||||
passcodeAutoLockOptions: any
|
passcodeAutoLockOptions: any;
|
||||||
user: any
|
user: any;
|
||||||
mutable: any
|
mutable: any;
|
||||||
importData: any
|
importData: any;
|
||||||
|
encryptionStatusString: string;
|
||||||
|
server: string;
|
||||||
|
encryptionEnabled: boolean;
|
||||||
|
selectedAutoLockInterval: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AccountMenuCtrl extends PureViewCtrl {
|
class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
|
||||||
|
|
||||||
public appVersion: string
|
public appVersion: string
|
||||||
private syncStatus?: SyncOpStatus
|
private syncStatus?: SyncOpStatus
|
||||||
@@ -117,15 +122,12 @@ class AccountMenuCtrl extends PureViewCtrl {
|
|||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
super.$onInit();
|
super.$onInit();
|
||||||
this.initProps({
|
|
||||||
closeFunction: this.closeFunction
|
|
||||||
});
|
|
||||||
this.syncStatus = this.application!.getSyncStatus();
|
this.syncStatus = this.application!.getSyncStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this.$timeout(() => {
|
this.$timeout(() => {
|
||||||
this.props.closeFunction();
|
this.closeFunction?.();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,7 +505,7 @@ class AccountMenuCtrl extends PureViewCtrl {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
submitPasscodeForm() {
|
async submitPasscodeForm() {
|
||||||
const passcode = this.getState().formData.passcode!;
|
const passcode = this.getState().formData.passcode!;
|
||||||
if (passcode !== this.getState().formData.confirmPasscode!) {
|
if (passcode !== this.getState().formData.confirmPasscode!) {
|
||||||
this.application!.alertService!.alert(
|
this.application!.alertService!.alert(
|
||||||
@@ -511,16 +513,23 @@ class AccountMenuCtrl extends PureViewCtrl {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(this.getState().formData.changingPasscode
|
|
||||||
? this.application!.changePasscode(passcode)
|
const onBeforeUnload = window.onbeforeunload;
|
||||||
: this.application!.setPasscode(passcode)
|
try {
|
||||||
).then(() => {
|
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({
|
this.setFormDataState({
|
||||||
passcode: undefined,
|
passcode: undefined,
|
||||||
confirmPasscode: undefined,
|
confirmPasscode: undefined,
|
||||||
showPasscodeForm: false
|
showPasscodeForm: false
|
||||||
});
|
});
|
||||||
});
|
} finally {
|
||||||
|
window.onbeforeunload = onBeforeUnload;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async changePasscodePressed() {
|
async changePasscodePressed() {
|
||||||
|
|||||||
@@ -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 =
|
export const STRING_CONFIRM_APP_QUIT_DURING_UPGRADE =
|
||||||
"The encryption upgrade is in progress. You may lose data if you quit the app. " +
|
"The encryption upgrade is in progress. You may lose data if you quit the app. " +
|
||||||
"Are you sure you want to quit?"
|
"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?"
|
||||||
|
|||||||
Reference in New Issue
Block a user