Move web pages to their own package
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DeleteReplyPage.kt
diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt
new file mode 100644 (file)
index 0000000..f9c51a3
--- /dev/null
@@ -0,0 +1,36 @@
+package net.pterodactylus.sone.web.pages
+
+import net.pterodactylus.sone.utils.isPOST
+import net.pterodactylus.sone.web.pages.SoneTemplatePage
+import net.pterodactylus.sone.web.WebInterface
+import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.util.template.Template
+import net.pterodactylus.util.template.TemplateContext
+
+/**
+ * This page lets the user delete a reply.
+ */
+class DeleteReplyPage(template: Template, webInterface: WebInterface):
+               SoneTemplatePage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, true) {
+
+       override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+               val replyId = request.httpRequest.getPartAsStringFailsafe("reply", 36)
+               templateContext["reply"] = replyId
+               val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256)
+               templateContext["returnPage"] = returnPage
+               if (request.isPOST) {
+                       val reply = webInterface.core.getPostReply(replyId).orNull() ?: throw RedirectException("noPermission.html")
+                       if (!reply.sone.isLocal) {
+                               throw RedirectException("noPermission.html")
+                       }
+                       if (request.httpRequest.isPartSet("confirmDelete")) {
+                               webInterface.core.deleteReply(reply)
+                               throw RedirectException(returnPage)
+                       }
+                       if (request.httpRequest.isPartSet("abortDelete")) {
+                               throw RedirectException(returnPage)
+                       }
+               }
+       }
+
+}