Move web pages to their own package
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DeleteReplyPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.utils.isPOST
4 import net.pterodactylus.sone.web.pages.SoneTemplatePage
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.FreenetRequest
7 import net.pterodactylus.util.template.Template
8 import net.pterodactylus.util.template.TemplateContext
9
10 /**
11  * This page lets the user delete a reply.
12  */
13 class DeleteReplyPage(template: Template, webInterface: WebInterface):
14                 SoneTemplatePage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, true) {
15
16         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
17                 val replyId = request.httpRequest.getPartAsStringFailsafe("reply", 36)
18                 templateContext["reply"] = replyId
19                 val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256)
20                 templateContext["returnPage"] = returnPage
21                 if (request.isPOST) {
22                         val reply = webInterface.core.getPostReply(replyId).orNull() ?: throw RedirectException("noPermission.html")
23                         if (!reply.sone.isLocal) {
24                                 throw RedirectException("noPermission.html")
25                         }
26                         if (request.httpRequest.isPartSet("confirmDelete")) {
27                                 webInterface.core.deleteReply(reply)
28                                 throw RedirectException(returnPage)
29                         }
30                         if (request.httpRequest.isPartSet("abortDelete")) {
31                                 throw RedirectException(returnPage)
32                         }
33                 }
34         }
35
36 }