From 2d43e1c34852e4a95b4512715888f438b405270a Mon Sep 17 00:00:00 2001 From: Maddy Guthridge Date: Sun, 29 Sep 2024 21:32:01 +1000 Subject: [PATCH 1/3] Split admin panel into distinct components --- src/routes/admin/+page.svelte | 105 +++++----------------------- src/routes/admin/GitSettings.svelte | 93 ++++++++++++++++++++++++ src/routes/admin/ReloadData.svelte | 9 +++ 3 files changed, 118 insertions(+), 89 deletions(-) create mode 100644 src/routes/admin/GitSettings.svelte create mode 100644 src/routes/admin/ReloadData.svelte diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte index ebdc403b..d9a7741c 100644 --- a/src/routes/admin/+page.svelte +++ b/src/routes/admin/+page.svelte @@ -1,37 +1,25 @@ Admin - {data.globals.config.siteName} - - + + - + @@ -42,70 +30,9 @@
-
- {#if data.repo} -

Git status

-

Current branch: {data.repo.branch}

-

Current commit: {data.repo.commit}

-

- {#if data.repo.behind} - {data.repo.behind} commits behind. - {/if} - {#if data.repo.ahead} - {data.repo.ahead} commits ahead. - {/if} -

- - - {#if data.repo.behind} - - {:else if data.repo.ahead} - - {/if} - - - {#if !data.repo.clean} - -

Changes

- -
    - {#each data.repo.changes as change} - {#if change.from} -
  • Rename {change.from} to ({change.path})
  • - {:else if change.index === '?'} -
  • Create {change.path}
  • - {:else if change.index === 'D'} -
  • Delete {change.path}
  • - {:else} -
  • Update {change.path}
  • - {/if} - {/each} -
- -
- - -
- {/if} - - {:else} -

Git is currently not in use

- - You can use a Git repository to back up your portfolio data. Enter the - clone URL for an empty Git repository and it will be set up for you. - -
- - -
- {/if} -
-
-

Reload data from disk

- If you have edited your data manually, you can use this button to - refresh it. - -
+ + +
diff --git a/src/routes/admin/GitSettings.svelte b/src/routes/admin/GitSettings.svelte new file mode 100644 index 00000000..a357b3ef --- /dev/null +++ b/src/routes/admin/GitSettings.svelte @@ -0,0 +1,93 @@ + + +
+ {#if data.repo} +

Git status

+

Current branch: {data.repo.branch}

+

Current commit: {data.repo.commit}

+

+ {#if data.repo.behind} + {data.repo.behind} commits behind. + {/if} + {#if data.repo.ahead} + {data.repo.ahead} commits ahead. + {/if} +

+ + + {#if data.repo.behind} + + {:else if data.repo.ahead} + + {/if} + + + {#if data.repo.clean} +

Changes

+ Working tree clean. + {:else} +

Changes

+ +
    + {#each data.repo.changes as change} + {#if change.from} +
  • Rename {change.from} to ({change.path})
  • + {:else if change.index === "?"} +
  • Create {change.path}
  • + {:else if change.index === "D"} +
  • Delete {change.path}
  • + {:else} +
  • Update {change.path}
  • + {/if} + {/each} +
+ +
+ + +
+ {/if} + {:else} +

Git is currently not in use

+ + You can use a Git repository to back up your portfolio data. Enter the clone + URL for an empty Git repository and it will be set up for you. + +
+ + +
+ {/if} +
diff --git a/src/routes/admin/ReloadData.svelte b/src/routes/admin/ReloadData.svelte new file mode 100644 index 00000000..ddb7c460 --- /dev/null +++ b/src/routes/admin/ReloadData.svelte @@ -0,0 +1,9 @@ + + +
+

Reload data from disk

+ If you have edited your data manually, you can use this button to refresh it. + +
From 819178067d7598e9b063e8607b3ea0efa40b7294 Mon Sep 17 00:00:00 2001 From: Maddy Guthridge Date: Sun, 29 Sep 2024 21:32:07 +1000 Subject: [PATCH 2/3] Implement password changing --- src/routes/admin/ChangePassword.svelte | 63 ++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/routes/admin/ChangePassword.svelte diff --git a/src/routes/admin/ChangePassword.svelte b/src/routes/admin/ChangePassword.svelte new file mode 100644 index 00000000..9730348c --- /dev/null +++ b/src/routes/admin/ChangePassword.svelte @@ -0,0 +1,63 @@ + + +
+

Change authentication

+
+

+ Username +
+ +

+

+ Original password +
+ +

+

+ New password +
+ +

+

+ Repeat new password +
+ +

+ {#if newPassword != repeatNewPassword} +

New passwords much match

+ {/if} +

+ +

+
+
From 7ddf8aa3d88b91d065186eab9e8093d0d2f71a3a Mon Sep 17 00:00:00 2001 From: Maddy Guthridge Date: Sun, 29 Sep 2024 22:16:49 +1000 Subject: [PATCH 3/3] QOL: make login page redirect to previous page on success --- src/components/navbar/Navbar.svelte | 36 ++++++++------ src/routes/admin/+page.svelte | 2 + src/routes/admin/LogOutAll.svelte | 15 ++++++ src/routes/admin/login/+page.server.ts | 3 +- src/routes/admin/login/+page.svelte | 65 ++++++++++++++++++-------- 5 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 src/routes/admin/LogOutAll.svelte diff --git a/src/components/navbar/Navbar.svelte b/src/components/navbar/Navbar.svelte index 3ff6c13d..efe77aad 100644 --- a/src/components/navbar/Navbar.svelte +++ b/src/components/navbar/Navbar.svelte @@ -1,11 +1,11 @@ @@ -38,7 +48,7 @@ {config.siteShortName} / {#each path.slice(0, -1) as p, i} {p.txt} - {'/ '} + {"/ "} {/each} {path[path.length - 1].txt} @@ -48,14 +58,14 @@ {#if loggedIn} - + {:else if loggedIn !== undefined} - + {/if} - + {#if dev} diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte index d9a7741c..75e2d9d9 100644 --- a/src/routes/admin/+page.svelte +++ b/src/routes/admin/+page.svelte @@ -6,6 +6,7 @@ import GitSettings from "./GitSettings.svelte"; import ChangePassword from "./ChangePassword.svelte"; import ReloadData from "./ReloadData.svelte"; + import LogOutAll from "./LogOutAll.svelte"; export let data: import("./$types").PageData; @@ -32,6 +33,7 @@
+
diff --git a/src/routes/admin/LogOutAll.svelte b/src/routes/admin/LogOutAll.svelte new file mode 100644 index 00000000..d099f452 --- /dev/null +++ b/src/routes/admin/LogOutAll.svelte @@ -0,0 +1,15 @@ + + +
+

Log out of all sessions

+

This will sign you out on all of your devices (including this one).

+ +
diff --git a/src/routes/admin/login/+page.server.ts b/src/routes/admin/login/+page.server.ts index 92f2dd1e..a28b8f4b 100644 --- a/src/routes/admin/login/+page.server.ts +++ b/src/routes/admin/login/+page.server.ts @@ -12,7 +12,8 @@ export async function load(req) { loggedIn = true; } catch { /* empty */ } if (loggedIn) { - redirect(303, '/admin'); + // If they are logged in, redirect them to the `from` URL if it exists. + redirect(303, req.url.searchParams.get("from") || '/'); } const globals = await getPortfolioGlobals(); return { globals }; diff --git a/src/routes/admin/login/+page.svelte b/src/routes/admin/login/+page.svelte index 87124ebb..1a49adc4 100644 --- a/src/routes/admin/login/+page.svelte +++ b/src/routes/admin/login/+page.svelte @@ -1,29 +1,41 @@ login - {data.globals.config.siteName} - - + + - + @@ -32,8 +44,8 @@ config={data.globals.config} loggedIn={false} path={[ - { txt: 'Admin', url: 'admin' }, - { txt: 'Login', url: 'login' }, + { txt: "Admin", url: "admin" }, + { txt: "Login", url: "login" }, ]} /> @@ -41,17 +53,32 @@
-

Login

+

Login

Username

- +

Password

- +

- +