feat: 'forgot passcode' on unlock priviledges modal

This commit is contained in:
Baptiste Grob
2020-06-30 17:24:46 +02:00
parent 4a07ef797e
commit 6052392833
3 changed files with 68 additions and 15 deletions

View File

@@ -11,26 +11,44 @@
.sk-panel-content .sk-panel-content
.sk-panel-section .sk-panel-section
div(ng-repeat="type in ctrl.state.types") div(ng-repeat="type in ctrl.state.types")
.sk-p.sk-bold.sk-panel-row .sk-p.sk-bold.sk-panel-row.centered
strong {{ctrl.promptForChallenge(type)}} strong {{ctrl.promptForChallenge(type)}}
.sk-panel-row .sk-panel-row
input.sk-input.contrast( input.sk-input.contrast(
ng-model="ctrl.state.values[type].value" ng-model="ctrl.state.values[type].value"
should-focus="$index == 0" should-focus="$index == 0"
sn-autofocus="true" sn-autofocus="true"
sn-enter="ctrl.submit()" , sn-enter="ctrl.submit()" ,
ng-change="ctrl.onTextValueChange(type)" ng-change="ctrl.onTextValueChange(type)"
type="password" type="password"
) )
.sk-panel-row .sk-panel-row.centered
label.sk-label.danger( label.sk-label.danger(
ng-if="ctrl.state.values[type].invalid" ng-if="ctrl.state.values[type].invalid"
) Invalid authentication. Please try again. ) Invalid authentication. Please try again.
.sk-panel-row
.sk-panel-footer.extra-padding .sk-panel-footer.extra-padding
.sk-button.info.big.block.bold( .sk-button.info.big.block.bold(
ng-click="ctrl.submit()", ng-click="ctrl.submit()",
ng-class="{'info' : !ctrl.state.processing, 'neutral': ctrl.state.processing}" ng-class="{'info' : !ctrl.state.processing, 'neutral': ctrl.state.processing}"
ng-disabled="ctrl.state.processing" ng-disabled="ctrl.state.processing"
) )
.sk-label {{ctrl.state.processing ? 'Generating Keys...' : 'Submit'}} .sk-label {{ctrl.state.processing ? 'Generating Keys...' : 'Submit'}}
.sk-panel-footer(ng-if="ctrl.state.showForgotPasscodeLink")
a.sk-panel-row.sk-a.info.centered(
ng-if="!ctrl.state.forgotPasscode"
ng-click="ctrl.onForgotPasscodeClick()"
) Forgot your passcode?
p.sk-panel-row.sk-p(ng-if="ctrl.state.forgotPasscode").
{{
ctrl.state.hasAccount
? "If you forgot your local passcode, your only option is to clear
your local data from this device and sign back in to your account."
: "If you forgot your local passcode, your only option is
to delete your data."
}}
a.sk-panel-row.sk-a.danger.centered(
ng-if="ctrl.state.forgotPasscode"
ng-click="ctrl.destroyLocalData()"
) Delete Local Data
.sk-panel-row

View File

@@ -5,9 +5,12 @@ import {
ChallengeValue, ChallengeValue,
removeFromArray, removeFromArray,
Challenge, Challenge,
ChallengeReason,
} from 'snjs'; } from 'snjs';
import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl'; import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl';
import { WebDirective } from '@/types'; import { WebDirective } from '@/types';
import { confirmDialog } from '@/services/alertService';
import { STRING_SIGN_OUT_CONFIRMATION } from '@/strings';
type InputValue = { type InputValue = {
value: string value: string
@@ -19,7 +22,9 @@ type Values = Record<ChallengeType, InputValue>
type ChallengeModalState = { type ChallengeModalState = {
types: ChallengeType[] types: ChallengeType[]
values: Partial<Values> values: Partial<Values>
processing: boolean processing: boolean,
forgotPasscode: boolean,
showForgotPasscodeLink: boolean,
} }
class ChallengeModalCtrl extends PureViewCtrl { class ChallengeModalCtrl extends PureViewCtrl {
@@ -27,6 +32,7 @@ class ChallengeModalCtrl extends PureViewCtrl {
private processingTypes: ChallengeType[] = [] private processingTypes: ChallengeType[] = []
application!: WebApplication application!: WebApplication
challenge!: Challenge challenge!: Challenge
private cancelable = false
/* @ngInject */ /* @ngInject */
constructor( constructor(
@@ -51,10 +57,15 @@ class ChallengeModalCtrl extends PureViewCtrl {
invalid: false invalid: false
}; };
} }
const showForgotPasscodeLink = this.challenge.reason === ChallengeReason.ApplicationUnlock
this.cancelable = !showForgotPasscodeLink
this.setState({ this.setState({
types: types, types,
values: values, values,
processing: false processing: false,
forgotPasscode: false,
showForgotPasscodeLink,
hasAccount: this.application.hasAccount(),
}); });
this.application.setChallengeCallbacks({ this.application.setChallengeCallbacks({
challenge: this.challenge, challenge: this.challenge,
@@ -94,13 +105,29 @@ class ChallengeModalCtrl extends PureViewCtrl {
} }
} }
async destroyLocalData() {
if (await confirmDialog({
text: STRING_SIGN_OUT_CONFIRMATION,
confirmButtonStyle: "danger"
})) {
await this.application.signOut();
this.dismiss();
};
}
cancel() { cancel() {
// if (!this.cancelable) { if (!this.cancelable) {
// return; return;
// } }
this.dismiss(); this.dismiss();
} }
onForgotPasscodeClick() {
this.setState({
forgotPasscode: true
});
}
onTextValueChange(challenge: ChallengeType) { onTextValueChange(challenge: ChallengeType) {
const values = this.getState().values; const values = this.getState().values;
values[challenge]!.invalid = false; values[challenge]!.invalid = false;

View File

@@ -12,7 +12,15 @@
} }
#privileges-modal { #privileges-modal {
width: 700px; width: 400px;
input {
text-align: center;
}
.sk-panel-header {
justify-content: center;
}
table { table {
margin-bottom: 12px; margin-bottom: 12px;