Skip to content

Commit

Permalink
fix: correctly set/change passcode
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Aug 26, 2020
1 parent 696f34b commit a63bfd8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
45 changes: 27 additions & 18 deletions app/assets/javascripts/directives/views/accountMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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?.();
});
}

Expand Down Expand Up @@ -503,24 +505,31 @@ class AccountMenuCtrl extends PureViewCtrl {
});
}

submitPasscodeForm() {
async submitPasscodeForm() {
const passcode = this.getState().formData.passcode!;
if (passcode !== this.getState().formData.confirmPasscode!) {
this.application!.alertService!.alert(
STRING_NON_MATCHING_PASSCODES
);
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() {
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?"

0 comments on commit a63bfd8

Please sign in to comment.