diff --git a/src/main/java/eu/m724/talkpages/auth/AuthResource.java b/src/main/java/eu/m724/talkpages/auth/AuthResource.java index 7678426..9fa50cf 100644 --- a/src/main/java/eu/m724/talkpages/auth/AuthResource.java +++ b/src/main/java/eu/m724/talkpages/auth/AuthResource.java @@ -1,10 +1,14 @@ package eu.m724.talkpages.auth; +import eu.m724.talkpages.orm.entity.auth.Account; import eu.m724.talkpages.orm.entity.auth.Session; +import eu.m724.talkpages.page.action.AccountService; import io.quarkus.qute.CheckedTemplate; import io.quarkus.qute.TemplateInstance; import io.quarkus.security.Authenticated; import io.quarkus.security.identity.SecurityIdentity; +import io.vertx.core.http.HttpClientRequest; +import io.vertx.core.http.HttpServerRequest; import jakarta.inject.Inject; import jakarta.ws.rs.*; import jakarta.ws.rs.core.*; @@ -27,19 +31,28 @@ public class AuthResource { public static native TemplateInstance auth(String message); public static native TemplateInstance authenticated(String username); public static native TemplateInstance register(String username, String message); + public static native TemplateInstance delete(); } @GET @Path("/") public TemplateInstance auth(@QueryParam("message") String message) { if (identity.isAnonymous()) { + // not logged in return Templates.auth(message); } else { + // logged in String username = identity.getPrincipal().getName(); return Templates.authenticated(username); } } + @GET + @Path("/delete") + public TemplateInstance delete() { + return Templates.delete(); + } + @GET @Path("/register") public TemplateInstance register(@QueryParam("username") String username, @QueryParam("message") String message) { @@ -141,4 +154,29 @@ public class AuthResource { .build(); } } + + + + @POST + @Path("/action/delete") + public Response actionDelete(@Context HttpServerRequest request, MultivaluedMap formData) { + if (!formData.getFirst("confirm").equals("on")) { + return Response.temporaryRedirect(URI.create("/auth/delete")).status(Response.Status.SEE_OTHER).build(); + } + + Account account; + if (identity.isAnonymous()) { + account = Account.findByName(request.remoteAddress().hostAddress()); + } else { + Session session = identity.getAttribute("session"); + account = session.getAccount(); + } + + if (account != null) { + authService.delete(account); + } + + // TODO perhaps status messages + return Response.temporaryRedirect(URI.create("/")).status(Response.Status.SEE_OTHER).build(); + } } diff --git a/src/main/java/eu/m724/talkpages/auth/AuthService.java b/src/main/java/eu/m724/talkpages/auth/AuthService.java index 90ffe12..96c9f31 100644 --- a/src/main/java/eu/m724/talkpages/auth/AuthService.java +++ b/src/main/java/eu/m724/talkpages/auth/AuthService.java @@ -46,6 +46,16 @@ public class AuthService { session.delete(); } + @Transactional + void delete(Account account) { + account.getRevisions().forEach(pageRevision -> { + // TODO + }); + // TODO delete user pages after they appear + account.delete(); + account.persistAndFlush(); + } + @Transactional Session validateSessionToken(String sessionToken) { Session session = Session.find("token", sessionToken).firstResult(); diff --git a/src/main/resources/templates/AuthResource/authenticated.html b/src/main/resources/templates/AuthResource/authenticated.html index 794f3a6..3dada1a 100644 --- a/src/main/resources/templates/AuthResource/authenticated.html +++ b/src/main/resources/templates/AuthResource/authenticated.html @@ -2,5 +2,8 @@ {#pageTitle}Account{/pageTitle}

Logged in as {username}

-

Log out

+ {/include} \ No newline at end of file diff --git a/src/main/resources/templates/AuthResource/delete.html b/src/main/resources/templates/AuthResource/delete.html new file mode 100644 index 0000000..288a58c --- /dev/null +++ b/src/main/resources/templates/AuthResource/delete.html @@ -0,0 +1,38 @@ +{#include layout} + {#pageTitle}Delete account{/pageTitle} + + {#if user:loggedIn} +

Logged in as {user:name}

+ +

Right after you click the button:

+ + {#else} +

+ Logged in as IP address {user:name} +
+ Your IP address is also an account, it's stored and treated as such. +

+ +

Right after you click the button:

+ + {/if} + +

While data is deleted on our side, it probably has been saved on third party archiving websites, legally or not. This is beyond our control, and we take no responsibility for it.

+ +
+ + +
+ +
+{/include} \ No newline at end of file