Replace delete profile field ajax page with Kotlin version
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / CreateReplyPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.text.TextFilter
4 import net.pterodactylus.sone.utils.isPOST
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 post a reply to a post.
12  */
13 class CreateReplyPage(template: Template, webInterface: WebInterface):
14                 SoneTemplatePage("createReply.html", template, "Page.CreateReply.Title", webInterface, true) {
15
16         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
17                 val postId = request.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this }
18                 val text = request.httpRequest.getPartAsStringFailsafe("text", 65536).trim().apply { templateContext["text"] = this }
19                 val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256).apply { templateContext["returnPage"] = this }
20                 if (request.isPOST) {
21                         if (text == "") {
22                                 templateContext["errorTextEmpty"] = true
23                                 return
24                         }
25                         val post = webInterface.core.getPost(postId).orNull() ?: throw RedirectException("noPermission.html")
26                         val sender = webInterface.core.getLocalSone(request.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(request.toadletContext)
27                         webInterface.core.createReply(sender, post, TextFilter.filter(request.httpRequest.getHeader("Host"), text))
28                         throw RedirectException(returnPage)
29                 }
30         }
31
32 }