X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FDeletePostPage.java;h=c8fd20f2edc680c62c846b652c16507a22e607dd;hp=ea8aeffbee3cd9bcff9889a98833896859edb869;hb=45f92ec63dbf8134d92ceed67294faa38117b195;hpb=309334f7379f58c848225e1bf47676bc40bfe5b2 diff --git a/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java b/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java index ea8aeff..c8fd20f 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java @@ -18,9 +18,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Lets the user delete a post they made. @@ -38,7 +39,7 @@ public class DeletePostPage extends SoneTemplatePage { * The Sone web interface */ public DeletePostPage(Template template, WebInterface webInterface) { - super("deletePost.html", template, "Page.DeletePost.Title", webInterface); + super("deletePost.html", template, "Page.DeletePost.Title", webInterface, true); } // @@ -49,35 +50,31 @@ public class DeletePostPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); - String postId = request.getHttpRequest().getParam("post", null); - if (postId == null) { - postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36); - } - Post post = webInterface.core().getPost(postId); - Sone currentSone = getCurrentSone(request.getToadletContext()); - if (!post.getSone().equals(currentSone)) { - throw new RedirectException("noPermission.html"); - } - if (request.getMethod() == Method.POST) { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { + super.processTemplate(request, templateContext); + if (request.getMethod() == Method.GET) { + String postId = request.getHttpRequest().getParam("post"); + String returnPage = request.getHttpRequest().getParam("returnPage"); + Post post = webInterface.getCore().getPost(postId); + templateContext.set("post", post); + templateContext.set("returnPage", returnPage); + return; + } else if (request.getMethod() == Method.POST) { + String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36); + String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); + Post post = webInterface.getCore().getPost(postId); + if (!webInterface.getCore().isLocalSone(post.getSone())) { + throw new RedirectException("noPermission.html"); + } if (request.getHttpRequest().isPartSet("confirmDelete")) { - currentSone.removePost(post); + webInterface.getCore().deletePost(post); + throw new RedirectException(returnPage); + } else if (request.getHttpRequest().isPartSet("abortDelete")) { + throw new RedirectException(returnPage); } - throw new RedirectException("index.html"); + templateContext.set("post", post); + templateContext.set("returnPage", returnPage); } } - // - // SONETEMPLATEPAGE METHODS - // - - /** - * {@inheritDoc} - */ - @Override - protected boolean requiresLogin() { - return true; - } - }