1 package net.pterodactylus.sone.web
3 import net.pterodactylus.sone.text.TextFilter
4 import net.pterodactylus.sone.web.page.FreenetRequest
5 import net.pterodactylus.util.template.Template
6 import net.pterodactylus.util.template.TemplateContext
7 import net.pterodactylus.util.web.Method.POST
10 * This page lets the user post a reply to a post.
12 class CreateReplyPage(template: Template, webInterface: WebInterface):
13 SoneTemplatePage("createReply.html", template, "Page.CreateReply.Title", webInterface, true) {
15 override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
16 val postId = request.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this }
17 val text = request.httpRequest.getPartAsStringFailsafe("text", 65536).trim().apply { templateContext["text"] = this }
18 val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256).apply { templateContext["returnPage"] = this }
19 if (request.method == POST) {
21 templateContext["errorTextEmpty"] = true
24 val post = webInterface.core.getPost(postId).orNull() ?: throw RedirectException("noPermission.html")
25 val sender = webInterface.core.getLocalSone(request.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(request.toadletContext)
26 webInterface.core.createReply(sender, post, TextFilter.filter(request.httpRequest.getHeader("Host"), text))
27 throw RedirectException(returnPage)