diff --git a/src/lib/server/ap.js b/src/lib/server/ap.js new file mode 100644 index 0000000..52d1b23 --- /dev/null +++ b/src/lib/server/ap.js @@ -0,0 +1,39 @@ +const loginResponse = { + id: '87bcb6de-bb70-11ee-b719-6756da82e80f', + username: 'hax0r', + acct: 'hax0r', + display_name: 'Jane Doe', + bot: false, + created_at: '2024-01-13T01:23:45.000Z', + note: '

Hackse for life

', + url: 'https://example.com/@hax0r', + avatar: 'https://avatars.example.com/hax0r', + role: { name: 'user' } +}; + +let username = loginResponse.username; + +export const requests = { + get: (url) => { + if (url === '/profile') { + return Promise.resolve({ + ...loginResponse, + username + }); + } + + return Promise.reject(new Error('Unauthorized')); + }, + post: (url, params) => { + if (url === '/login') { + username = params.account; + + return Promise.resolve({ + ...loginResponse, + username: params.account + }); + } + + return Promise.reject(new Error('Invalid Login')); + } +}; diff --git a/src/routes/account/login/+page.server.js b/src/routes/account/login/+page.server.js new file mode 100644 index 0000000..6e4accb --- /dev/null +++ b/src/routes/account/login/+page.server.js @@ -0,0 +1,35 @@ +import { fail, redirect } from '@sveltejs/kit'; + +import { requests } from '$lib/server/ap.js'; + +/** @type {import('./$types').Actions} */ +export const actions = { + login: async ({ cookies, request, url }) => { + const formData = await request.formData(); + const server = formData.get('server'); + const account = formData.get('account'); + const passphrase = formData.get('passphrase'); + + if (!account) { + return fail(400, { account, missing: true }); + } + + if (!passphrase) { + return fail(400, { account, incorrect: true }); + } + + try { + // TODO: Consumre response? + await requests.post('/login', { account, passphrase }); + } catch (exc) { + console.error(exc); + return fail(400, { account, incorrect: true }); + } + + if (url.searchParams.has('redirectTo')) { + redirect(303, url.searchParams.get('redirectTo')); + } + + redirect(303, '/profile'); + } +}; diff --git a/src/routes/account/login/+page.svelte b/src/routes/account/login/+page.svelte index 042a5ac..082e6aa 100644 --- a/src/routes/account/login/+page.svelte +++ b/src/routes/account/login/+page.svelte @@ -1,11 +1,18 @@ + +

Log in

To use Anvil with your F2 account, fill in your credentials.

-
+
+ {#if form?.missing}

The account field is required.

{/if} + {#if form?.incorrect}

Account or password wrong.

{/if} - Log in -
+ +
diff --git a/src/routes/profile/+page.server.js b/src/routes/profile/+page.server.js new file mode 100644 index 0000000..23d4721 --- /dev/null +++ b/src/routes/profile/+page.server.js @@ -0,0 +1,19 @@ +import { requests } from '$lib/server/ap.js'; + +/** @type {import('./$types').PageServerLoad} */ +export async function load({ params }) { + const locale = 'en-US'; + const profile = await requests.get('/profile'); + + return { + server: { + name: 'F2' + }, + user: { + ...profile, + created_at_formatted: new Intl.DateTimeFormat(locale).format(new Date(profile.created_at)), + created_with: 'Anvil', + instance: 'example.com' + } + }; +} diff --git a/src/routes/profile/+page.svelte b/src/routes/profile/+page.svelte new file mode 100644 index 0000000..f881d59 --- /dev/null +++ b/src/routes/profile/+page.svelte @@ -0,0 +1,85 @@ + + +
+ +
+ +
+ +
+
+ created {@html data.user.created_at_formatted} + + or + +
+ +
+ +
+
+

+ Profile for + {@html data.user.display_name} +

+

(she/her)

+
+ + {@html data.user.username}@{@html data.user.instance} + +
+ + +
+
+
+
+ +
+
+

Projects

+

+ No projects added yet. + Add a project + or + import a project. +

+
+
+ +
+
+

Activities

+
    +
  • + + + + ✴️ + Apr 23, 2023 - account set up + + + + + The F2 account @{@html data.user.username}@{@html data.user.instance} was successfully + set up within {@html data.user.created_with} + + +
  • +
+
+
+