Challenge modal
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import angular from 'angular';
|
||||
import { challengeToString } from 'snjs';
|
||||
import { humanReadableList } from '@/utils';
|
||||
|
||||
export class GodService {
|
||||
/* @ngInject */
|
||||
@@ -25,42 +23,24 @@ export class GodService {
|
||||
angular.element(document.body).append(el);
|
||||
}
|
||||
|
||||
async promptForChallenges(challenges) {
|
||||
return new Promise((resolve) => {
|
||||
const scope = this.$rootScope.$new(true);
|
||||
scope.challenges = challenges.slice();
|
||||
scope.onSubmit = (responses) => {
|
||||
resolve(responses);
|
||||
};
|
||||
const el = this.$compile(
|
||||
"<challenge-modal class='sk-modal' challenges='challenges' on-submit='onSubmit'></challenge-modal>"
|
||||
)(scope);
|
||||
angular.element(document.body).append(el);
|
||||
});
|
||||
promptForChallenge(challenge, orchestrator) {
|
||||
const scope = this.$rootScope.$new(true);
|
||||
scope.challenge = challenge;
|
||||
scope.orchestrator = orchestrator;
|
||||
const el = this.$compile(
|
||||
"<challenge-modal " +
|
||||
"class='sk-modal' challenge='challenge' orchestrator='orchestrator'>" +
|
||||
"</challenge-modal>"
|
||||
)(scope);
|
||||
angular.element(document.body).append(el);
|
||||
}
|
||||
|
||||
async performProtocolUpgrade() {
|
||||
const errors = await this.application.upgradeProtocolVersion({
|
||||
requiresChallengeResponses: async (challenges) => {
|
||||
return this.promptForChallenges(challenges);
|
||||
},
|
||||
handleFailedChallengeResponses: async (responses) => {
|
||||
const names = responses.map((r) => challengeToString(r.challenge));
|
||||
const formatted = humanReadableList(names);
|
||||
return new Promise((resolve) => {
|
||||
this.application.alertService.alert({
|
||||
text: `Invalid authentication value for ${formatted}. Please try again.`,
|
||||
onClose: () => {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
const errors = await this.application.upgradeProtocolVersion();
|
||||
if (errors.length === 0) {
|
||||
this.application.alertService.alert({
|
||||
text: "Success! Your encryption version has been upgraded." +
|
||||
" You'll be asked to enter your credentials again on other devices you're signed into."
|
||||
" You'll be asked to enter your credentials again on other devices you're signed into."
|
||||
});
|
||||
} else {
|
||||
this.application.alertService.alert({
|
||||
|
||||
Reference in New Issue
Block a user