add passphrase reset
This commit is contained in:
@ -1,93 +0,0 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { emit } from '@tauri-apps/api/event';
|
||||
import { getRootCause } from '../lib/errors.js';
|
||||
|
||||
import { appState } from '../lib/state.js';
|
||||
import { navigate } from '../lib/routing.js';
|
||||
import Link from '../ui/Link.svelte';
|
||||
import ErrorAlert from '../ui/ErrorAlert.svelte';
|
||||
import Spinner from '../ui/Spinner.svelte';
|
||||
|
||||
|
||||
let errorMsg = null;
|
||||
let alert;
|
||||
let AccessKeyId, SecretAccessKey, passphrase, confirmPassphrase
|
||||
|
||||
function confirm() {
|
||||
if (passphrase !== confirmPassphrase) {
|
||||
errorMsg = 'Passphrases do not match.'
|
||||
}
|
||||
}
|
||||
|
||||
let saving = false;
|
||||
async function save() {
|
||||
if (passphrase !== confirmPassphrase) {
|
||||
alert.shake();
|
||||
return;
|
||||
}
|
||||
|
||||
let credentials = {AccessKeyId, SecretAccessKey};
|
||||
try {
|
||||
saving = true;
|
||||
await invoke('save_credentials', {credentials, passphrase});
|
||||
emit('credentials-event', 'entered');
|
||||
if ($appState.currentRequest) {
|
||||
navigate('Approve');
|
||||
}
|
||||
else {
|
||||
navigate('Home');
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
const root = getRootCause(e);
|
||||
if (e.code === 'GetSession' && root.code) {
|
||||
errorMsg = `Error response from AWS (${root.code}): ${root.msg}`;
|
||||
}
|
||||
else {
|
||||
// some of the built-in Tauri errors are plain strings,
|
||||
// so fall back to e if e.msg doesn't exist
|
||||
errorMsg = e.msg || e;
|
||||
}
|
||||
|
||||
// if the alert already existed, shake it
|
||||
if (alert) {
|
||||
alert.shake();
|
||||
}
|
||||
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
emit('credentials-event', 'enter-canceled');
|
||||
navigate('Home');
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<form action="#" on:submit|preventDefault="{save}" class="form-control space-y-4 max-w-sm m-auto p-4 h-screen justify-center">
|
||||
<h2 class="text-2xl font-bold text-center">Enter your credentials</h2>
|
||||
|
||||
{#if errorMsg}
|
||||
<ErrorAlert bind:this="{alert}">{errorMsg}</ErrorAlert>
|
||||
{/if}
|
||||
|
||||
<input type="text" placeholder="AWS Access Key ID" bind:value="{AccessKeyId}" class="input input-bordered" />
|
||||
<input type="password" placeholder="AWS Secret Access Key" bind:value="{SecretAccessKey}" class="input input-bordered" />
|
||||
<input type="password" placeholder="Passphrase" bind:value="{passphrase}" class="input input-bordered" />
|
||||
<input type="password" placeholder="Re-enter passphrase" bind:value={confirmPassphrase} class="input input-bordered" on:change={confirm} />
|
||||
|
||||
<button type="submit" class="btn btn-primary">
|
||||
{#if saving }
|
||||
<Spinner class="w-5 h-5" thickness="12"/>
|
||||
{:else}
|
||||
Submit
|
||||
{/if}
|
||||
</button>
|
||||
<Link target={cancel} hotkey="Escape">
|
||||
<button class="btn btn-sm btn-outline w-full">Cancel</button>
|
||||
</Link>
|
||||
</form>
|
@ -10,6 +10,7 @@
|
||||
import ErrorAlert from '../ui/ErrorAlert.svelte';
|
||||
import Link from '../ui/Link.svelte';
|
||||
import PassphraseInput from '../ui/PassphraseInput.svelte';
|
||||
import ResetPassphrase from './passphrase/ResetPassphrase.svelte';
|
||||
import Spinner from '../ui/Spinner.svelte';
|
||||
import vaultDoorSvg from '../assets/vault_door.svg?raw';
|
||||
|
||||
@ -75,4 +76,6 @@
|
||||
Submit
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<ResetPassphrase />
|
||||
</form>
|
||||
|
@ -6,6 +6,7 @@
|
||||
import ErrorAlert from '../../ui/ErrorAlert.svelte';
|
||||
import Link from '../../ui/Link.svelte';
|
||||
import PassphraseInput from '../../ui/PassphraseInput.svelte';
|
||||
import ResetPassphrase from './ResetPassphrase.svelte';
|
||||
import Spinner from '../../ui/Spinner.svelte';
|
||||
|
||||
export let cancellable = false;
|
||||
@ -81,4 +82,8 @@
|
||||
<button type="button" class="btn btn-outline btn-sm w-full">Cancel</button>
|
||||
</Link>
|
||||
{/if}
|
||||
|
||||
{#if $appState.sessionStatus === 'locked'}
|
||||
<ResetPassphrase />
|
||||
{/if}
|
||||
</form>
|
||||
|
42
src/views/passphrase/ResetPassphrase.svelte
Normal file
42
src/views/passphrase/ResetPassphrase.svelte
Normal file
@ -0,0 +1,42 @@
|
||||
<script>
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { appState } from '../../lib/state.js';
|
||||
|
||||
|
||||
let modal, error, alert;
|
||||
|
||||
function reset() {
|
||||
try {
|
||||
invoke('reset_session');
|
||||
$appState.sessionStatus = 'empty';
|
||||
}
|
||||
catch (e) {
|
||||
if (alert) alert.shake();
|
||||
error = e;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<button type="button" class="self-end text-sm text-secondary/75 hover:text-secondary hover:underline focus:ring-accent" on:click={modal.showModal()}>
|
||||
Reset passphrase
|
||||
</button>
|
||||
|
||||
<dialog class="modal" bind:this={modal}>
|
||||
<div class="modal-box space-y-6">
|
||||
{#if error}
|
||||
<ErrorAlert>{error}</ErrorAlert>
|
||||
{/if}
|
||||
<h3 class="text-lg font-bold">Delete all credentials?</h3>
|
||||
<div class="space-y-2">
|
||||
<p>Credentials are encrypted with your current passphrase and will be lost if the passphrase is reset.</p>
|
||||
<p>Are you sure you want to reset your passphrase and delete all saved credentials?</p>
|
||||
</div>
|
||||
<div class="modal-action">
|
||||
<form method="dialog" class="flex gap-x-4">
|
||||
<button autofocus class="btn btn-outline">Cancel</button>
|
||||
<button class="btn btn-error" on:click={reset}>Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
Reference in New Issue
Block a user