Protocol upgrading WIP

This commit is contained in:
Mo Bitar
2020-03-15 18:29:01 -05:00
parent 5a6a41933a
commit 148e840757
15 changed files with 956 additions and 403 deletions

View File

@@ -68,7 +68,6 @@ class AccountMenuCtrl extends PureCtrl {
super.onAppLaunch();
this.setState(this.refreshedCredentialState());
this.loadHost();
this.checkForSecurityUpdate();
this.reloadAutoLockInterval();
this.loadBackupsAvailability();
}
@@ -106,13 +105,6 @@ class AccountMenuCtrl extends PureCtrl {
});
}
async checkForSecurityUpdate() {
const available = await this.godService.checkForSecurityUpdate();
this.setState({
securityUpdateAvailable: available
});
}
async loadBackupsAvailability() {
const hasUser = !isNullOrUndefined(this.application.getUser());
const hasPasscode = this.application.hasPasscode();
@@ -278,9 +270,9 @@ class AccountMenuCtrl extends PureCtrl {
}
}
openPasswordWizard(type) {
openPasswordWizard() {
this.close();
this.godService.presentPasswordWizard(type);
this.godService.presentPasswordWizard();
}
async openPrivilegesModal() {

View File

@@ -0,0 +1,91 @@
import template from '%/directives/challenge-modal.pug';
import { Challenges, ChallengeResponse } from 'snjs';
import { PureCtrl } from '@Controllers';
class ChallengeModalCtrl extends PureCtrl {
/* @ngInject */
constructor(
$scope,
$element,
$timeout,
application,
appState
) {
super($scope, $timeout, application, appState);
this.$element = $element;
}
$onInit() {
super.$onInit();
this.values = {};
this.setState({
challenges: this.challenges
});
}
promptForChallenge(challenge) {
if(challenge === Challenges.LocalPasscode) {
return 'Enter your application passcode';
} else {
return 'Enter your account password';
}
}
cancel() {
this.dismiss();
this.onCancel && this.onCancel();
}
isChallengeInFailureState(challenge) {
if (!this.failedChallenges) {
return false;
}
return this.failedChallenges.find((candidate) => {
return candidate === challenge;
}) != null;
}
validate() {
const failed = [];
for (const cred of this.state.challenges) {
const value = this.values[cred];
if (!value || value.length === 0) {
failed.push(cred);
}
}
this.failedChallenges = failed;
return failed.length === 0;
}
async submit() {
if (!this.validate()) {
return;
}
const responses = Object.keys(this.values).map((key) => {
const challenge = Number(key);
const value = this.values[key];
return new ChallengeResponse(challenge, value);
});
this.onSubmit(responses);
this.dismiss();
}
dismiss() {
this.$element.remove();
}
}
export class ChallengeModal {
constructor() {
this.restrict = 'E';
this.template = template;
this.controller = ChallengeModalCtrl;
this.controllerAs = 'ctrl';
this.bindToController = true;
this.scope = {
onSubmit: '=',
onCancel: '=',
challenges: '='
};
}
}

View File

@@ -1,5 +1,6 @@
export { AccountMenu } from './accountMenu';
export { ActionsMenu } from './actionsMenu';
export { ChallengeModal } from './challengeModal';
export { ComponentModal } from './componentModal';
export { ComponentView } from './componentView';
export { ConflictResolutionModal } from './conflictResolutionModal';

View File

@@ -153,7 +153,6 @@ class PasswordWizardCtrl extends PureCtrl {
? this.state.formData.currentPassword
: this.state.formData.newPassword;
const response = await this.application.changePassword({
email: this.application.getUser().email,
currentPassword: this.state.formData.currentPassword,
newPassword: newPassword
});