Replace upload image page with Kotlin version
[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.WebInterface
5 import net.pterodactylus.sone.web.page.FreenetRequest
6 import net.pterodactylus.util.template.Template
7 import net.pterodactylus.util.template.TemplateContext
8
9 /**
10  * This page lets the user delete a reply.
11  */
12 class DeleteReplyPage(template: Template, webInterface: WebInterface):
13                 SoneTemplatePage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, true) {
14
15         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
16                 if (request.isPOST) {
17                         val replyId = request.httpRequest.getPartAsStringFailsafe("reply", 36)
18                         val reply = webInterface.core.getPostReply(replyId).orNull() ?: throw RedirectException("noPermission.html")
19                         if (!reply.sone.isLocal) {
20                                 throw RedirectException("noPermission.html")
21                         }
22                         val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256)
23                         if (request.httpRequest.isPartSet("confirmDelete")) {
24                                 webInterface.core.deleteReply(reply)
25                                 throw RedirectException(returnPage)
26                         }
27                         if (request.httpRequest.isPartSet("abortDelete")) {
28                                 throw RedirectException(returnPage)
29                         }
30                         templateContext["reply"] = replyId
31                         templateContext["returnPage"] = returnPage
32                         return
33                 }
34                 templateContext["reply"] = request.httpRequest.getParam("reply")
35                 templateContext["returnPage"] = request.httpRequest.getParam("returnPage")
36         }
37
38 }