From cdb8ccbf97607fc045223810ddb6e4444c29baf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sof=C3=ADa=20Aritz?= Date: Sat, 29 Jun 2024 16:50:06 +0200 Subject: [PATCH] more things --- identity-api/src/auth.js | 7 ++ identity-api/src/index.js | 29 +++++ identity-web/src/lib/api.ts | 17 +++ identity-web/src/lib/stores.ts | 21 +++- .../src/routes/auth/account/+page.svelte | 113 +++++++++++++++++- .../src/routes/dashboard/Entries.svelte | 12 +- 6 files changed, 193 insertions(+), 6 deletions(-) diff --git a/identity-api/src/auth.js b/identity-api/src/auth.js index 2e7dab6..a494182 100644 --- a/identity-api/src/auth.js +++ b/identity-api/src/auth.js @@ -19,6 +19,13 @@ export async function startAuth() { limits: { assetCount: 5, }, + heirs: [ + { + contactMethod: "email", + name: "Sofía Aritz", + value: "sofi@sofiaritz.com", + }, + ], entries: JSON.parse(`[{"id":"0","creationDate":"2024-04-13T00:00:00.000Z","feelings":["active","happy"],"base":{"kind":"song","id":[{"provider":"spotify","id":"53mChDyESfwn9Dz8poHRf6"}],"link":["https://open.spotify.com/track/53mChDyESfwn9Dz8poHRf6"],"title":"Taking What's Not Yours","artist":"TV Girl"},"assets":[]},{"id":"1","creationDate":"2024-04-13T00:00:00.000Z","feelings":[],"base":{"kind":"album","id":[{"provider":"spotify","id":"1d2PspdXmwrBEcOtquCvzT"}],"link":["https://open.spotify.com/album/1d2PspdXmwrBEcOtquCvzT"],"title":"CHASER","artist":"femtanyl"},"assets":[]},{"id":"2","creationDate":"2024-04-26T00:00:00.000Z","feelings":["excited"],"title":"SalmorejoTech 2024","description":"SalmorejoTech is a great tech-event. I met some people and everything went great! :)","base":{"kind":"event"},"assets":[]},{"id":"3","creationDate":"2024-06-26T00:00:00.000Z","feelings":["happy","relaxed"],"title":"Playing Minecraft with Mr. Pablo","description":"Mr. Pablo is my friend, she is a great friend. We spent a good time playing Minecraft. I am lucky to have a friend like him.","base":{"kind":"memory"},"assets":[]},{"id":"4","creationDate":"2024-01-01T00:00:00.000Z","feelings":["excited","nervous"],"description":"New Year, New me! I'm really excited about what's going to happen this year, lots of changes. Changes may be scary, but they usually are for good!","base":{"kind":"feeling"},"assets":["f9d040d6-598c-4483-952f-08e7d35d5420.jpg"]},{"id":"5","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy","relaxed"],"title":"The park","description":"The park is a really chill place where I can go and relax for a bit before going to work.","base":{"kind":"environment"},"assets":[]},{"id":"6","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy"],"description":"This day has been a great day! I've talked with my friends.","base":{"kind":"date","referencedDate":"2024-04-27T00:00:00.000Z"},"assets":[]},{"id":"0a","creationDate":"2024-04-13T00:00:00.000Z","feelings":["active","happy"],"base":{"kind":"song","id":[{"provider":"spotify","id":"53mChDyESfwn9Dz8poHRf6"}],"link":["https://open.spotify.com/track/53mChDyESfwn9Dz8poHRf6"],"title":"Taking What's Not Yours","artist":"TV Girl"},"assets":[]},{"id":"1a","creationDate":"2024-04-13T00:00:00.000Z","feelings":[],"base":{"kind":"album","id":[{"provider":"spotify","id":"1d2PspdXmwrBEcOtquCvzT"}],"link":["https://open.spotify.com/album/1d2PspdXmwrBEcOtquCvzT"],"title":"CHASER","artist":"femtanyl"},"assets":[]},{"id":"2a","creationDate":"2024-04-26T00:00:00.000Z","feelings":["excited"],"title":"SalmorejoTech 2024","description":"SalmorejoTech is a great tech-event. I met some people and everything went great! :)","base":{"kind":"event"},"assets":[]},{"id":"3a","creationDate":"2024-06-26T00:00:00.000Z","feelings":["happy","relaxed"],"title":"Playing Minecraft with Mr. Pablo","description":"Mr. Pablo is my friend, she is a great friend. We spent a good time playing Minecraft. I am lucky to have a friend like him.","base":{"kind":"memory"},"assets":[]},{"id":"4a","creationDate":"2024-01-01T00:00:00.000Z","feelings":["excited","nervous"],"description":"New Year, New me! I'm really excited about what's going to happen this year, lots of changes. Changes may be scary, but they usually are for good!","base":{"kind":"feeling"},"assets":["f9d040d6-598c-4483-952f-08e7d35d5420.jpg"]},{"id":"5a","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy","relaxed"],"title":"The park","description":"The park is a really chill place where I can go and relax for a bit before going to work.","base":{"kind":"environment"},"assets":[]},{"id":"6a","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy"],"description":"This day has been a great day! I've talked with my friends.","base":{"kind":"date","referencedDate":"2024-04-27T00:00:00.000Z"},"assets":[]},{"id":"0b","creationDate":"2024-04-13T00:00:00.000Z","feelings":["active","happy"],"base":{"kind":"song","id":[{"provider":"spotify","id":"53mChDyESfwn9Dz8poHRf6"}],"link":["https://open.spotify.com/track/53mChDyESfwn9Dz8poHRf6"],"title":"Taking What's Not Yours","artist":"TV Girl"},"assets":[]},{"id":"1b","creationDate":"2024-04-13T00:00:00.000Z","feelings":[],"base":{"kind":"album","id":[{"provider":"spotify","id":"1d2PspdXmwrBEcOtquCvzT"}],"link":["https://open.spotify.com/album/1d2PspdXmwrBEcOtquCvzT"],"title":"CHASER","artist":"femtanyl"},"assets":[]},{"id":"2b","creationDate":"2024-04-26T00:00:00.000Z","feelings":["excited"],"title":"SalmorejoTech 2024","description":"SalmorejoTech is a great tech-event. I met some people and everything went great! :)","base":{"kind":"event"},"assets":[]},{"id":"3b","creationDate":"2024-06-26T00:00:00.000Z","feelings":["happy","relaxed"],"title":"Playing Minecraft with Mr. Pablo","description":"Mr. Pablo is my friend, she is a great friend. We spent a good time playing Minecraft. I am lucky to have a friend like him.","base":{"kind":"memory"},"assets":[]},{"id":"4b","creationDate":"2024-01-01T00:00:00.000Z","feelings":["excited","nervous"],"description":"New Year, New me! I'm really excited about what's going to happen this year, lots of changes. Changes may be scary, but they usually are for good!","base":{"kind":"feeling"},"assets":["f9d040d6-598c-4483-952f-08e7d35d5420.jpg"]},{"id":"5b","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy","relaxed"],"title":"The park","description":"The park is a really chill place where I can go and relax for a bit before going to work.","base":{"kind":"environment"},"assets":[]},{"id":"6b","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy"],"description":"This day has been a great day! I've talked with my friends.","base":{"kind":"date","referencedDate":"2024-04-27T00:00:00.000Z"},"assets":[]},{"id":"0c","creationDate":"2024-04-13T00:00:00.000Z","feelings":["active","happy"],"base":{"kind":"song","id":[{"provider":"spotify","id":"53mChDyESfwn9Dz8poHRf6"}],"link":["https://open.spotify.com/track/53mChDyESfwn9Dz8poHRf6"],"title":"Taking What's Not Yours","artist":"TV Girl"},"assets":[]},{"id":"1c","creationDate":"2024-04-13T00:00:00.000Z","feelings":[],"base":{"kind":"album","id":[{"provider":"spotify","id":"1d2PspdXmwrBEcOtquCvzT"}],"link":["https://open.spotify.com/album/1d2PspdXmwrBEcOtquCvzT"],"title":"CHASER","artist":"femtanyl"},"assets":[]},{"id":"2c","creationDate":"2024-04-26T00:00:00.000Z","feelings":["excited"],"title":"SalmorejoTech 2024","description":"SalmorejoTech is a great tech-event. I met some people and everything went great! :)","base":{"kind":"event"},"assets":[]},{"id":"3c","creationDate":"2024-06-26T00:00:00.000Z","feelings":["happy","relaxed"],"title":"Playing Minecraft with Mr. Pablo","description":"Mr. Pablo is my friend, she is a great friend. We spent a good time playing Minecraft. I am lucky to have a friend like him.","base":{"kind":"memory"},"assets":[]},{"id":"4c","creationDate":"2024-01-01T00:00:00.000Z","feelings":["excited","nervous"],"description":"New Year, New me! I'm really excited about what's going to happen this year, lots of changes. Changes may be scary, but they usually are for good!","base":{"kind":"feeling"},"assets":["f9d040d6-598c-4483-952f-08e7d35d5420.jpg"]},{"id":"5c","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy","relaxed"],"title":"The park","description":"The park is a really chill place where I can go and relax for a bit before going to work.","base":{"kind":"environment"},"assets":[]},{"id":"6c","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy"],"description":"This day has been a great day! I've talked with my friends.","base":{"kind":"date","referencedDate":"2024-04-27T00:00:00.000Z"},"assets":[]},{"id":"0d","creationDate":"2024-04-13T00:00:00.000Z","feelings":["active","happy"],"base":{"kind":"song","id":[{"provider":"spotify","id":"53mChDyESfwn9Dz8poHRf6"}],"link":["https://open.spotify.com/track/53mChDyESfwn9Dz8poHRf6"],"title":"Taking What's Not Yours","artist":"TV Girl"},"assets":[]},{"id":"1d","creationDate":"2024-04-13T00:00:00.000Z","feelings":[],"base":{"kind":"album","id":[{"provider":"spotify","id":"1d2PspdXmwrBEcOtquCvzT"}],"link":["https://open.spotify.com/album/1d2PspdXmwrBEcOtquCvzT"],"title":"CHASER","artist":"femtanyl"},"assets":[]},{"id":"2d","creationDate":"2024-04-26T00:00:00.000Z","feelings":["excited"],"title":"SalmorejoTech 2024","description":"SalmorejoTech is a great tech-event. I met some people and everything went great! :)","base":{"kind":"event"},"assets":[]},{"id":"3d","creationDate":"2024-06-26T00:00:00.000Z","feelings":["happy","relaxed"],"title":"Playing Minecraft with Mr. Pablo","description":"Mr. Pablo is my friend, she is a great friend. We spent a good time playing Minecraft. I am lucky to have a friend like him.","base":{"kind":"memory"},"assets":[]},{"id":"4d","creationDate":"2024-01-01T00:00:00.000Z","feelings":["excited","nervous"],"description":"New Year, New me! I'm really excited about what's going to happen this year, lots of changes. Changes may be scary, but they usually are for good!","base":{"kind":"feeling"},"assets":["f9d040d6-598c-4483-952f-08e7d35d5420.jpg"]},{"id":"5d","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy","relaxed"],"title":"The park","description":"The park is a really chill place where I can go and relax for a bit before going to work.","base":{"kind":"environment"},"assets":[]},{"id":"6d","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy"],"description":"This day has been a great day! I've talked with my friends.","base":{"kind":"date","referencedDate":"2024-04-27T00:00:00.000Z"},"assets":[]},{"id":"0e","creationDate":"2024-04-13T00:00:00.000Z","feelings":["active","happy"],"base":{"kind":"song","id":[{"provider":"spotify","id":"53mChDyESfwn9Dz8poHRf6"}],"link":["https://open.spotify.com/track/53mChDyESfwn9Dz8poHRf6"],"title":"Taking What's Not Yours","artist":"TV Girl"},"assets":[]},{"id":"1e","creationDate":"2024-04-13T00:00:00.000Z","feelings":[],"base":{"kind":"album","id":[{"provider":"spotify","id":"1d2PspdXmwrBEcOtquCvzT"}],"link":["https://open.spotify.com/album/1d2PspdXmwrBEcOtquCvzT"],"title":"CHASER","artist":"femtanyl"},"assets":[]},{"id":"2e","creationDate":"2024-04-26T00:00:00.000Z","feelings":["excited"],"title":"SalmorejoTech 2024","description":"SalmorejoTech is a great tech-event. I met some people and everything went great! :)","base":{"kind":"event"},"assets":[]},{"id":"3e","creationDate":"2024-06-26T00:00:00.000Z","feelings":["happy","relaxed"],"title":"Playing Minecraft with Mr. Pablo","description":"Mr. Pablo is my friend, she is a great friend. We spent a good time playing Minecraft. I am lucky to have a friend like him.","base":{"kind":"memory"},"assets":[]},{"id":"4e","creationDate":"2024-01-01T00:00:00.000Z","feelings":["excited","nervous"],"description":"New Year, New me! I'm really excited about what's going to happen this year, lots of changes. Changes may be scary, but they usually are for good!","base":{"kind":"feeling"},"assets":["f9d040d6-598c-4483-952f-08e7d35d5420.jpg"]},{"id":"5e","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy","relaxed"],"title":"The park","description":"The park is a really chill place where I can go and relax for a bit before going to work.","base":{"kind":"environment"},"assets":[]},{"id":"6e","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy"],"description":"This day has been a great day! I've talked with my friends.","base":{"kind":"date","referencedDate":"2024-04-27T00:00:00.000Z"},"assets":[]},{"id":"0f","creationDate":"2024-04-13T00:00:00.000Z","feelings":["active","happy"],"base":{"kind":"song","id":[{"provider":"spotify","id":"53mChDyESfwn9Dz8poHRf6"}],"link":["https://open.spotify.com/track/53mChDyESfwn9Dz8poHRf6"],"title":"Taking What's Not Yours","artist":"TV Girl"},"assets":[]},{"id":"1f","creationDate":"2024-04-13T00:00:00.000Z","feelings":[],"base":{"kind":"album","id":[{"provider":"spotify","id":"1d2PspdXmwrBEcOtquCvzT"}],"link":["https://open.spotify.com/album/1d2PspdXmwrBEcOtquCvzT"],"title":"CHASER","artist":"femtanyl"},"assets":[]},{"id":"2f","creationDate":"2024-04-26T00:00:00.000Z","feelings":["excited"],"title":"SalmorejoTech 2024","description":"SalmorejoTech is a great tech-event. I met some people and everything went great! :)","base":{"kind":"event"},"assets":[]},{"id":"3f","creationDate":"2024-06-26T00:00:00.000Z","feelings":["happy","relaxed"],"title":"Playing Minecraft with Mr. Pablo","description":"Mr. Pablo is my friend, she is a great friend. We spent a good time playing Minecraft. I am lucky to have a friend like him.","base":{"kind":"memory"},"assets":[]},{"id":"4f","creationDate":"2024-01-01T00:00:00.000Z","feelings":["excited","nervous"],"description":"New Year, New me! I'm really excited about what's going to happen this year, lots of changes. Changes may be scary, but they usually are for good!","base":{"kind":"feeling"},"assets":["f9d040d6-598c-4483-952f-08e7d35d5420.jpg"]},{"id":"5f","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy","relaxed"],"title":"The park","description":"The park is a really chill place where I can go and relax for a bit before going to work.","base":{"kind":"environment"},"assets":[]},{"id":"6f","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy"],"description":"This day has been a great day! I've talked with my friends.","base":{"kind":"date","referencedDate":"2024-04-27T00:00:00.000Z"},"assets":[]},{"id":"0g","creationDate":"2024-04-13T00:00:00.000Z","feelings":["active","happy"],"base":{"kind":"song","id":[{"provider":"spotify","id":"53mChDyESfwn9Dz8poHRf6"}],"link":["https://open.spotify.com/track/53mChDyESfwn9Dz8poHRf6"],"title":"Taking What's Not Yours","artist":"TV Girl"},"assets":[]},{"id":"1g","creationDate":"2024-04-13T00:00:00.000Z","feelings":[],"base":{"kind":"album","id":[{"provider":"spotify","id":"1d2PspdXmwrBEcOtquCvzT"}],"link":["https://open.spotify.com/album/1d2PspdXmwrBEcOtquCvzT"],"title":"CHASER","artist":"femtanyl"},"assets":[]},{"id":"2g","creationDate":"2024-04-26T00:00:00.000Z","feelings":["excited"],"title":"SalmorejoTech 2024","description":"SalmorejoTech is a great tech-event. I met some people and everything went great! :)","base":{"kind":"event"},"assets":[]},{"id":"3g","creationDate":"2024-06-26T00:00:00.000Z","feelings":["happy","relaxed"],"title":"Playing Minecraft with Mr. Pablo","description":"Mr. Pablo is my friend, she is a great friend. We spent a good time playing Minecraft. I am lucky to have a friend like him.","base":{"kind":"memory"},"assets":[]},{"id":"4g","creationDate":"2024-01-01T00:00:00.000Z","feelings":["excited","nervous"],"description":"New Year, New me! I'm really excited about what's going to happen this year, lots of changes. Changes may be scary, but they usually are for good!","base":{"kind":"feeling"},"assets":["f9d040d6-598c-4483-952f-08e7d35d5420.jpg"]},{"id":"5g","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy","relaxed"],"title":"The park","description":"The park is a really chill place where I can go and relax for a bit before going to work.","base":{"kind":"environment"},"assets":[]},{"id":"6g","creationDate":"2024-04-28T00:00:00.000Z","feelings":["happy"],"description":"This day has been a great day! I've talked with my friends.","base":{"kind":"date","referencedDate":"2024-04-27T00:00:00.000Z"},"assets":[]}]`) }, }; diff --git a/identity-api/src/index.js b/identity-api/src/index.js index 780afec..56e0ead 100644 --- a/identity-api/src/index.js +++ b/identity-api/src/index.js @@ -144,6 +144,35 @@ app.get("/entry/list", { }, }) +app.post("/auth/heirs", { + async handler(request, reply) { + let jwt = request.headers["authorization"].replace("Bearer", "").trim(); + let { payload } = await auth.verifyJwt(jwt); + + if (payload.uid == null) { + reply.status(401); + return; + } + + let user = await auth.user(payload.uid); + user.heirs = request.body; + + await auth.updateUser(payload.uid, user); + }, + schema: { + headers: { + type: "object", + properties: { + authorization: { type: "string" }, + }, + required: ["authorization"], + }, + body: { + type: "array", + } + } +}) + app.get("/auth/genkey", { async handler(request) { let jwt = request.headers["authorization"].replace("Bearer", "").trim(); diff --git a/identity-web/src/lib/api.ts b/identity-web/src/lib/api.ts index e4f9bc2..24f8d49 100644 --- a/identity-web/src/lib/api.ts +++ b/identity-web/src/lib/api.ts @@ -7,9 +7,16 @@ export type Credentials = { token: string, } +export type AccountHeir = { + contactMethod: "email", + name: string, + value: string, +} + export type Account = { uid: string, name: string, + heirs: AccountHeir[], } function sendRequest(path: string, credentials?: Credentials, request: RequestInit = {}, params: string = "") { @@ -88,6 +95,16 @@ export async function deleteEntry(credentials: Credentials, entry_id: string): P await sendRequest('/entry', credentials, { method: 'DELETE' }, `?entry_id=${entry_id}`) } +export async function updateHeirs(credentials: Credentials, heirs: AccountHeir[]): Promise { + await sendRequest('/auth/heirs', credentials, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(heirs), + }); +} + export async function uploadAsset(session_key: string, file: File): Promise { let url = new URL('/asset', ASSET_API_ENDPOINT); url.search = `?session_key=${session_key}` diff --git a/identity-web/src/lib/stores.ts b/identity-web/src/lib/stores.ts index 14817c0..c8c23d2 100644 --- a/identity-web/src/lib/stores.ts +++ b/identity-web/src/lib/stores.ts @@ -3,10 +3,14 @@ import { accountData, assetEndpoint, genSessionKey, type Account, type Credentia const CREDENTIALS_KEY = 'v0:credentials' +let _credentials: Credentials | null = null export const credentials = writable() credentials.subscribe((value) => { if (value != null) { - localStorage.setItem(CREDENTIALS_KEY, JSON.stringify(value)) + _credentials = value; + localStorage.setItem( CREDENTIALS_KEY, JSON.stringify(value)) + } else { + _credentials = null; } }) @@ -44,4 +48,19 @@ export async function initializeStores() { let asset_result = await assetEndpoint() asset_endpoint.set(asset_result) } +} + +export async function refreshAccount() { + if (_credentials == null) { + console.warn("Requested to refresh the user account but credentials are null.") + return; + } + + let refreshedAccount = await accountData(_credentials) + if ('error' in refreshedAccount) { + console.warn("Failed to refresh the user account.") + return; + } + + account.set(refreshedAccount) } \ No newline at end of file diff --git a/identity-web/src/routes/auth/account/+page.svelte b/identity-web/src/routes/auth/account/+page.svelte index 24ded02..df40240 100644 --- a/identity-web/src/routes/auth/account/+page.svelte +++ b/identity-web/src/routes/auth/account/+page.svelte @@ -1,14 +1,119 @@

Welcome back, {$account?.name}.

-

- The account panel is still work in progress, feel free to contact support with any inquires. -

+
+
+

Heirs

+ {#if $account?.heirs.length > 0} + + {/if} +
+ {#if !heirWizard && $account?.heirs.length === 0} +
+ +
+ {/if} + {#if heirWizard} +
+
+
+ + + {#if $errors.contactMethod != null} +

{$errors.contactMethod[0]}

+ {/if} +
+
+ + + {#if $errors.name != null} +

{$errors.name[0]}

+ {/if} +
+
+ + + {#if $errors.contactDetails != null} +

{$errors.contactDetails[0]}

+ {/if} +
+ +
+
+ {/if} + {#each $account?.heirs || [] as heir (heir.value)} +
+
+ Contact method: {heir.contactMethod} + +
+
+ {heir.name} · {heir.value} +
+
+ {/each} +
\ No newline at end of file diff --git a/identity-web/src/routes/dashboard/Entries.svelte b/identity-web/src/routes/dashboard/Entries.svelte index 2afc806..d2bc280 100644 --- a/identity-web/src/routes/dashboard/Entries.svelte +++ b/identity-web/src/routes/dashboard/Entries.svelte @@ -68,7 +68,10 @@ if (filters.searchQuery != null) { let fuse = new Fuse(entries, { keys: [ - "title", + { + name: "title", + weight: 2, + }, "description", ], }); @@ -87,6 +90,13 @@ $: applyFilters(filters) +{#if entries.length != filteredEntries.length && filteredEntries.length === 0} +
+
+ No results found +
+
+{/if} {#each filteredEntries as entry (entry.id)} extended = [e.detail.id, ...extended]}