X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FDeleteImagePage.java;h=3bbaf3dcb2986ad4f6315f9747465230278c8968;hp=84222ee71f743623dcc1ba1c8f4df69d71e1b65e;hb=a47643aed43d118ca68044f95451bb5374cdb332;hpb=eb0f0b56e248146f0523feb93c75f9dff5cedde1 diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteImagePage.java b/src/main/java/net/pterodactylus/sone/web/DeleteImagePage.java index 84222ee..3bbaf3d 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteImagePage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteImagePage.java @@ -1,5 +1,5 @@ /* - * Sone - DeleteImagePage.java - Copyright © 2011 David Roden + * Sone - DeleteImagePage.java - Copyright © 2011–2012 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,9 +18,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Image; -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; /** * Page that lets the user delete an {@link Image}. @@ -49,20 +50,24 @@ public class DeleteImagePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); + String imageId = (request.getMethod() == Method.POST) ? request.getHttpRequest().getPartAsStringFailsafe("image", 36) : request.getHttpRequest().getParam("image"); + Image image = webInterface.getCore().getImage(imageId, false); + if (image == null) { + throw new RedirectException("invalid.html"); + } + if (!webInterface.getCore().isLocalSone(image.getSone())) { + throw new RedirectException("noPermission.html"); + } if (request.getMethod() == Method.POST) { - String imageId = request.getHttpRequest().getPartAsStringFailsafe("image", 36); - Image image = webInterface.getCore().getImage(imageId, false); - if (image == null) { - throw new RedirectException("invalid.html"); - } - if (!webInterface.getCore().isLocalSone(image.getSone())) { - throw new RedirectException("noPermission.html"); + if (request.getHttpRequest().isPartSet("abortDelete")) { + throw new RedirectException("imageBrowser.html?image=" + image.getId()); } webInterface.getCore().deleteImage(image); throw new RedirectException("imageBrowser.html?album=" + image.getAlbum().getId()); } + templateContext.set("image", image); } }