From 66740dea41f2772d46e1b13b91ef0e7b1a68bfff Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 6 Feb 2023 16:40:14 -0800 Subject: new pinpad component --- package.json | 1 - pnpm-lock.yaml | 6 - src/components/Feed.svelte | 4 +- src/components/Password.svelte | 6 +- src/components/Pin.svelte | 26 +-- src/components/Pinpad.svelte | 81 ++++++++ src/components/RegisterOrLogin.svelte | 207 +++++++++------------ src/components/index.js | 1 + src/lib/nostr.js | 2 +- src/lib/utils.js | 2 +- src/locales/en.json | 2 +- src/routes/(app)/[username]/(profile)/+page.svelte | 5 +- .../[username]/(profile)/messages/+page.svelte | 4 +- src/routes/(app)/[username]/dashboard/+page.svelte | 2 +- src/routes/(app)/[username]/generate/+page.svelte | 6 +- .../[username]/settings/[...tab]/+page.svelte | 8 +- .../(app)/[username]/settings/[...tab]/_pos.svelte | 2 +- .../[username]/settings/[...tab]/_security.svelte | 161 ++++++---------- src/routes/(app)/disable2fa/+server.js | 4 +- src/routes/(app)/otpsecret/+server.js | 2 +- src/routes/(app)/send/[...text]/+page.svelte | 4 +- static/icons/eye-off.svg | 73 +++++++- static/icons/eye.svg | 52 +++++- 23 files changed, 397 insertions(+), 264 deletions(-) create mode 100644 src/components/Pinpad.svelte diff --git a/package.json b/package.json index b6b32ee6..908ec0bf 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "screenfull": "^6.0.2", "svelte": "^3.55.0", "svelte-outclick": "^3.3.3", - "svelte-pincode": "^2.2.0", "svelte-preprocess": "^4.10.7", "svelte-virtual-scroll-list": "^1.1.0", "sveltekit-i18n": "^2.2.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d072ee80..4f0d2ef2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,7 +26,6 @@ specifiers: screenfull: ^6.0.2 svelte: ^3.55.0 svelte-outclick: ^3.3.3 - svelte-pincode: ^2.2.0 svelte-preprocess: ^4.10.7 svelte-virtual-scroll-list: ^1.1.0 sveltekit-i18n: ^2.2.2 @@ -66,7 +65,6 @@ devDependencies: screenfull: 6.0.2 svelte: 3.55.0 svelte-outclick: 3.3.3_svelte@3.55.0 - svelte-pincode: 2.2.0 svelte-preprocess: 4.10.7_qs7rgzvahok4cbkjoy5bgypde4 svelte-virtual-scroll-list: 1.1.0_svelte@3.55.0 sveltekit-i18n: 2.2.2_svelte@3.55.0 @@ -2406,10 +2404,6 @@ packages: svelte: 3.55.0 dev: true - /svelte-pincode/2.2.0: - resolution: {integrity: sha512-zT2jOHffZqQ1dLmFAojfkdssKr8HGq1uSZQK1TCwD1/Mjrw2EGuKppQOh0q2pobm8AAGhvk7LKHnFtRUKsz80A==} - dev: true - /svelte-preprocess/4.10.7_qs7rgzvahok4cbkjoy5bgypde4: resolution: {integrity: sha512-sNPBnqYD6FnmdBrUmBCaqS00RyCsCpj2BG58A1JBswNF7b0OKviwxqVrOL/CKyJrLSClrSeqQv5BXNg2RUbPOw==} engines: {node: '>= 9.11.2'} diff --git a/src/components/Feed.svelte b/src/components/Feed.svelte index ab757fa1..7de087a7 100644 --- a/src/components/Feed.svelte +++ b/src/components/Feed.svelte @@ -4,7 +4,7 @@ import { Event } from '$comp'; import { browser } from '$app/environment'; import VirtualScroll from 'svelte-virtual-scroll-list'; - import { failure } from '$lib/utils'; + import { fail } from '$lib/utils'; import { sign, send } from '$lib/nostr'; export let events; @@ -34,7 +34,7 @@ events = events; } catch (e) { console.log(e, e.stack); - failure('Problem posting event'); + fail('Problem posting event'); } }; diff --git a/src/components/Password.svelte b/src/components/Password.svelte index fd39441c..a84c0b16 100644 --- a/src/components/Password.svelte +++ b/src/components/Password.svelte @@ -1,6 +1,6 @@ @@ -51,7 +51,7 @@ diff --git a/src/components/Pin.svelte b/src/components/Pin.svelte index 7225ac37..0db831ff 100644 --- a/src/components/Pin.svelte +++ b/src/components/Pin.svelte @@ -1,24 +1,28 @@ -
-
-

Please enter your PIN

- +
+
+

{title}

+
diff --git a/src/components/Pinpad.svelte b/src/components/Pinpad.svelte new file mode 100644 index 00000000..bf3778f7 --- /dev/null +++ b/src/components/Pinpad.svelte @@ -0,0 +1,81 @@ + + +
+
+
+ {#if hide} + + {:else} + + {/if} + +
+ +
+ {#each numPad as value} + {#if value === arrow} + + {:else} + + {/if} + {/each} +
+
+
diff --git a/src/components/RegisterOrLogin.svelte b/src/components/RegisterOrLogin.svelte index 7ac2fbb3..6c099178 100644 --- a/src/components/RegisterOrLogin.svelte +++ b/src/components/RegisterOrLogin.svelte @@ -1,28 +1,32 @@ +{#if need2fa} + +{/if} +
diff --git a/src/components/index.js b/src/components/index.js index 18a821ff..ab54e09f 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -1,3 +1,4 @@ +export { default as Pinpad } from './Pinpad.svelte'; export { default as Balance } from './Balance.svelte'; export { default as Lnurlp } from './Lnurlp.svelte'; export { default as Lnurlw } from './Lnurlw.svelte'; diff --git a/src/lib/nostr.js b/src/lib/nostr.js index 35d843b2..de19b477 100644 --- a/src/lib/nostr.js +++ b/src/lib/nostr.js @@ -3,7 +3,7 @@ import * as ecc from 'tiny-secp256k1'; import { generateMnemonic, entropyToMnemonic, mnemonicToEntropy, mnemonicToSeedSync } from 'bip39'; import { Buffer } from 'buffer'; import { bech32m } from 'bech32'; -import { bip32, failure, wait, post, stretch } from '$lib/utils'; +import { bip32, fail, wait, post, stretch } from '$lib/utils'; import { calculateId, signId } from 'nostr'; import { password as pw, passwordPrompt, pin, loginRedirect } from '$lib/store'; import { goto, invalidate } from '$app/navigation'; diff --git a/src/lib/utils.js b/src/lib/utils.js index d0b0b1c2..3a644e1f 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -101,7 +101,7 @@ export const warning = (m) => { } }); }; -export const failure = (m) => { +export const fail = (m) => { toast.pop(); toast.push(m, { theme: { diff --git a/src/locales/en.json b/src/locales/en.json index eb0039ac..b39571f6 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -241,7 +241,7 @@ "autoLock": "Auto-Lock Timer", "autoLockDescription": "Your account will go into a secure mode, requiring you to re-enter your credentials after a specified time:", "twofa": "2-Factor Authentication", - "twofaDescription": "Add an extra level of security to your device by enableing 2-factor authentication.", + "twofaDescription": "Add an extra level of security to your device by enabling 2-factor authentication.", "twofaSetup": "Set up 2FA", "twofaDisable": "Disable 2FA", "select": "Select", diff --git a/src/routes/(app)/[username]/(profile)/+page.svelte b/src/routes/(app)/[username]/(profile)/+page.svelte index 40c73ea4..1cf525a0 100644 --- a/src/routes/(app)/[username]/(profile)/+page.svelte +++ b/src/routes/(app)/[username]/(profile)/+page.svelte @@ -4,8 +4,11 @@ export let data; let { events, subject, user } = data; + let v;
- + {#if user?.id === subject.id} + + {/if}
diff --git a/src/routes/(app)/[username]/(profile)/messages/+page.svelte b/src/routes/(app)/[username]/(profile)/messages/+page.svelte index 00960534..db7b1ced 100644 --- a/src/routes/(app)/[username]/(profile)/messages/+page.svelte +++ b/src/routes/(app)/[username]/(profile)/messages/+page.svelte @@ -5,7 +5,7 @@ import { scale } from 'svelte/transition'; import { enhance } from '$app/forms'; import { Icon } from '$comp'; - import { back, failure, focus } from '$lib/utils'; + import { back, fail, focus } from '$lib/utils'; import { sign, send, encrypt, decrypt } from '$lib/nostr'; import { messages, password } from '$lib/store'; import { tick, onMount } from 'svelte'; @@ -64,7 +64,7 @@ sent = true; } catch (e) { - failure('Failed to send message'); + fail('Failed to send message'); delete $messages[user.pubkey][subject.pubkey][event.id]; $messages = $messages; } diff --git a/src/routes/(app)/[username]/dashboard/+page.svelte b/src/routes/(app)/[username]/dashboard/+page.svelte index d136943e..499034e6 100644 --- a/src/routes/(app)/[username]/dashboard/+page.svelte +++ b/src/routes/(app)/[username]/dashboard/+page.svelte @@ -1,6 +1,6 @@ {#if loaded && user.haspin && $pin?.length !== 6} - + {/if}
import { Icon, LocaleSelector, Toggle } from '$comp'; import { t } from '$lib/translations'; - import { success, failure } from '$lib/utils'; + import { success, fail } from '$lib/utils'; import { page } from '$app/stores'; export let user, rates; diff --git a/src/routes/(app)/[username]/settings/[...tab]/_security.svelte b/src/routes/(app)/[username]/settings/[...tab]/_security.svelte index cf969f1c..eb3b405e 100644 --- a/src/routes/(app)/[username]/settings/[...tab]/_security.svelte +++ b/src/routes/(app)/[username]/settings/[...tab]/_security.svelte @@ -1,80 +1,52 @@ @@ -155,31 +147,10 @@

{$t('user.settings.securityPINDescription')}

- {#if settingPin} -
-
-
- - - - - - - - -
-
- - - - - - - - -
-
-
+ {#if verifying} + + {:else if settingPin} + {:else}
-
- {$t('user.settings.oneTimeCode')}
- - - - - - - - -
- {:else if disabling2fa} -
- {$t('user.settings.oneTimeCode')}
- - - - - - - - -
+ {:else if user.twofa} - {:else} - {/if} + + {#if confirming2fa || disabling2fa} + + {/if}
diff --git a/src/routes/(app)/disable2fa/+server.js b/src/routes/(app)/disable2fa/+server.js index 13fcb2b9..b2bb07ec 100644 --- a/src/routes/(app)/disable2fa/+server.js +++ b/src/routes/(app)/disable2fa/+server.js @@ -1,4 +1,4 @@ -import { error } from '@sveltejs/kit'; +import { error, json } from '@sveltejs/kit'; import { auth, post } from '$lib/utils'; export async function POST({ cookies, request }) { @@ -6,7 +6,7 @@ export async function POST({ cookies, request }) { let body = await request.json(); let res = await post('/disable2fa', body, auth(cookies)); - return new Response(JSON.stringify(res)); + return json(res); } catch (e) { throw error(500, 'Problem disabling 2fa'); } diff --git a/src/routes/(app)/otpsecret/+server.js b/src/routes/(app)/otpsecret/+server.js index 31dbcec1..7d5c1ad9 100644 --- a/src/routes/(app)/otpsecret/+server.js +++ b/src/routes/(app)/otpsecret/+server.js @@ -9,7 +9,7 @@ export async function POST({ cookies, request }) { let uri = `otpauth://totp/coinos:${username}?secret=${secret}&period=30&digits=6&algorithm=SHA1&issuer=coinos`; return new Response(JSON.stringify({ secret, uri, qr: Qr.drawImg(uri, { size: 600 }) })); } catch (e) { - console.log(e); + if (e.message.includes('pin')) throw e; throw new error(500, 'Problem saving secret'); } } diff --git a/src/routes/(app)/send/[...text]/+page.svelte b/src/routes/(app)/send/[...text]/+page.svelte index e3d8091f..46f5e56a 100644 --- a/src/routes/(app)/send/[...text]/+page.svelte +++ b/src/routes/(app)/send/[...text]/+page.svelte @@ -6,7 +6,7 @@ import { browser } from '$app/environment'; import { t } from '$lib/translations'; import { AppHeader, Avatar, Icon, Spinner } from '$comp'; - import { back, failure } from '$lib/utils'; + import { back, fail } from '$lib/utils'; import { format, parseISO } from 'date-fns'; export let data; @@ -90,7 +90,7 @@

{$t('user.send.contacts')}