From 0e17224e71296cf6a0336c5a2e7340a3b63cd2dc Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 24 Oct 2022 22:26:13 -0700 Subject: pin code --- src/components/Pin.svelte | 44 +++++++++++++++++++++++++ src/components/index.js | 1 + src/lib/store.js | 1 + src/locales/en.json | 2 +- src/locales/es.json | 2 +- src/routes/[username]/settings/+page.server.js | 2 +- src/routes/[username]/settings/+page.svelte | 21 +++++++++--- src/routes/[username]/settings/_account.svelte | 5 ++- src/routes/[username]/settings/_security.svelte | 15 ++++++--- 9 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 src/components/Pin.svelte (limited to 'src') diff --git a/src/components/Pin.svelte b/src/components/Pin.svelte new file mode 100644 index 00000000..3e5769b0 --- /dev/null +++ b/src/components/Pin.svelte @@ -0,0 +1,44 @@ + + +
+
+

Please enter your PIN

+
+ + + + + + + + +
+ +
+ +
+
+
diff --git a/src/components/index.js b/src/components/index.js index d0af4c38..c3a5000c 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -1,3 +1,4 @@ +export { default as Pin } from './Pin.svelte'; export { default as Card } from './Card.svelte'; export { default as Lock } from './Lock.svelte'; export { default as Calendar } from './Calendar.svelte'; diff --git a/src/lib/store.js b/src/lib/store.js index e317ed24..4e5421ba 100644 --- a/src/lib/store.js +++ b/src/lib/store.js @@ -38,3 +38,4 @@ export const colorTheme = writable('from-primary to-gradient'); export const tempProfileFiles = writable(); export const avatarUpload = writable(); export const bannerUpload = writable(); +export const pin = writable(); diff --git a/src/locales/en.json b/src/locales/en.json index 60cd1b0e..b5aef47a 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -32,7 +32,7 @@ "bio": "Strategic & Project Management. Jack of all Trades. Can always find time to meet for coffee." }, "cole": { - "name": "Cole Goodwin", + "name": "Cole", "position": "Bitcoin Professional", "bio": "As a Certified Bitcoin Professional, Cole is a driven individual with a passion for freedom. He came across bitcoin in 2016 and studied it in depth. Now he wants to introduce the lightning network to as many users as possible." }, diff --git a/src/locales/es.json b/src/locales/es.json index 5fad6dd8..068d93a5 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -32,7 +32,7 @@ "bio": "Gestión Estratégica y de Proyectos. Ella es una todóloga. Siempre encuentra tiempo para reunirse a tomar un café." }, "cole": { - "name": "Cole Goodwin", + "name": "Cole", "position": "Profesional en Bitcoin", "bio": "Como profesional certificado de Bitcoin, Cole es una persona motivada y apasionada por la libertad. Encontró bitcoin en el año 2016 bitcoin y se dedicó a estudiarlo en profundidad. Ahora quiere presentar Lightning Network a tantos usuarios como sea posible." }, diff --git a/src/routes/[username]/settings/+page.server.js b/src/routes/[username]/settings/+page.server.js index deb4356e..ae7e0a78 100644 --- a/src/routes/[username]/settings/+page.server.js +++ b/src/routes/[username]/settings/+page.server.js @@ -3,7 +3,7 @@ import { auth, get, post } from '$lib/utils'; export const actions = { default: async ({ cookies, request }) => { - let form = Object.fromEntries(await request.formData()) + let form = Object.fromEntries(await request.formData()); let user = { ...(await get('/me', auth(cookies))), diff --git a/src/routes/[username]/settings/+page.svelte b/src/routes/[username]/settings/+page.svelte index a584fc56..7bd4ddcc 100644 --- a/src/routes/[username]/settings/+page.svelte +++ b/src/routes/[username]/settings/+page.svelte @@ -1,21 +1,28 @@ +{#if user.haspin && $pin?.length !== 6} + +{/if} +
+ +

{$t('user.settings.header')} @@ -74,7 +85,7 @@ class="z-10 fixed bottom-0 bg-white shadow border-t w-full flex justify-center items-center py-3" > select('profile')} + on:keydown={() => select('profile')}>Select { verifying = true; @@ -24,6 +26,7 @@ let locked; $: verifyCode.join('').length > 5 && checkPin(); let checkPin = async () => { + old = $current; if (locked) return; locked = true; @@ -35,7 +38,8 @@ try { if (pin.length > 5 && pin === verify) { - user.pin = pin; + user.haspin = true; + $current = pin; submit.click(); } else { failure('Pin mismatch, try again'); @@ -62,9 +66,9 @@ }; let togglePin = async () => { - if (user.pin) { + if (user.haspin) { try { - user.pin = null; + pin = null; submit.click(); } catch (e) { failure('Failed to disable pin'); @@ -109,7 +113,8 @@
- + + {verifying ? 'Verify' : 'Security'} PIN

{$t('user.settings.securityPINDescription')} @@ -141,7 +146,7 @@

{:else} {user.haspin ? 'Disable Pin' : 'Enable Pin'} {/if}

-- cgit v1.2.3