Change a couple of method argument names
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / CreatePostPage.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 create a new [Post].
12  */
13 class CreatePostPage(template: Template, webInterface: WebInterface):
14                 SoneTemplatePage("createPost.html", template, "Page.CreatePost.Title", webInterface, true) {
15
16         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
17                 val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
18                 templateContext["returnPage"] = returnPage
19                 if (freenetRequest.isPOST) {
20                         val text = freenetRequest.httpRequest.getPartAsStringFailsafe("text", 65536).trim()
21                         if (text == "") {
22                                 templateContext["errorTextEmpty"] = true
23                                 return
24                         }
25                         val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(freenetRequest.toadletContext)
26                         val recipient = webInterface.core.getSone(freenetRequest.httpRequest.getPartAsStringFailsafe("recipient", 43))
27                         webInterface.core.createPost(sender, recipient, TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text))
28                         throw RedirectException(returnPage)
29                 }
30         }
31
32 }