feat: self-service deletion API, reactivate account page

This commit is contained in:
sam 2024-12-19 16:13:05 +01:00
parent 8a2ffd7d69
commit 96725cc304
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
13 changed files with 183 additions and 17 deletions

View file

@ -16,8 +16,6 @@
data.member ? `/@${data.user.username}/${data.member.name}` : `/@${data.user.username}`,
);
console.log(data.user, !!data.member);
let reasons = $derived.by(() => {
const reasons = [];
for (const value of Object.values(ReportReason)) {

View file

@ -18,9 +18,37 @@
<h3>{$t("settings.general-information-tab")}</h3>
{#if data.user.deleted}
<div class="row mb-3">
{#if !data.user.suspended}
<div class="col-md">
<h4>{$t("settings.reactivate-header")}</h4>
<p>
{$t("settings.reactivate-explanation")}
</p>
<a href="/settings/reactivate" class="btn btn-success">
{$t("settings.reactivate-button")}
</a>
</div>
{/if}
<div class="col-md">
<h4>{$t("settings.force-delete-header")}</h4>
<p>
{$t("settings.force-delete-explanation")}
<strong>
{$t("settings.force-delete-warning")}
</strong>
</p>
<a href="/settings/force-delete" class="btn btn-danger">
{$t("settings.force-delete-button")}
</a>
</div>
</div>
{/if}
<div class="row mb-3">
<div class="col-md-9">
<h5>Change your username</h5>
<h5>{$t("settings.change-username-header")}</h5>
<form method="POST" action="?/changeUsername" use:enhance>
<FormGroup class="mb-3">
<InputGroup class="m-1 mt-3 w-md-75">
@ -80,6 +108,13 @@
<a class="btn btn-danger" href="/settings/force-log-out">{$t("settings.force-log-out-button")}</a>
</div>
{#if !data.user.deleted}
<div class="mb-3">
<h4>Delete your account</h4>
<p></p>
</div>
{/if}
<div>
<h4>{$t("settings.table-title")}</h4>

View file

@ -0,0 +1,23 @@
import { fastRequest } from "$api";
import ApiError, { ErrorCode } from "$api/error";
import { redirect } from "@sveltejs/kit";
export const load = async ({ parent, fetch, cookies }) => {
const { meUser } = await parent();
if (!meUser) redirect(303, "/");
if (meUser.suspended || !meUser.deleted)
throw new ApiError({
message: "You cannot use this page.",
status: 403,
code: ErrorCode.Forbidden,
});
await fastRequest("POST", "/self-delete/undelete", {
fetch,
cookies,
isInternal: true,
});
return { user: meUser! };
};

View file

@ -0,0 +1,20 @@
<script lang="ts">
import { t } from "$lib/i18n";
import type { PageData } from "./$types";
type Props = { data: PageData };
let { data }: Props = $props();
</script>
<div class="w-lg-75 mx-auto">
<h3>{$t("settings.reactivated-header")}</h3>
<p>{$t("settings.reactivated-explanation")}</p>
<div class="btn-group">
<a href="/settings" class="btn btn-primary">{$t("edit-profile.back-to-settings-tab")}</a>
<a href="/@{data.user.username}" class="btn btn-secondary">
{$t("error.back-to-profile-button")}
</a>
</div>
</div>