Add test for DI constructability of BookmarkPage
[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.data.Sone
4 import net.pterodactylus.sone.text.TextFilter
5 import net.pterodactylus.sone.utils.asOptional
6 import net.pterodactylus.sone.utils.isPOST
7 import net.pterodactylus.sone.web.WebInterface
8 import net.pterodactylus.sone.web.page.FreenetRequest
9 import net.pterodactylus.util.template.Template
10 import net.pterodactylus.util.template.TemplateContext
11
12 /**
13  * This page lets the user create a new [Post].
14  */
15 class CreatePostPage(template: Template, webInterface: WebInterface):
16                 LoggedInPage("createPost.html", template, "Page.CreatePost.Title", webInterface) {
17
18         override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
19                 val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
20                 templateContext["returnPage"] = returnPage
21                 if (freenetRequest.isPOST) {
22                         val text = freenetRequest.httpRequest.getPartAsStringFailsafe("text", 65536).trim()
23                         if (text == "") {
24                                 templateContext["errorTextEmpty"] = true
25                                 return
26                         }
27                         val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone
28                         val recipient = webInterface.core.getSone(freenetRequest.httpRequest.getPartAsStringFailsafe("recipient", 43))
29                         webInterface.core.createPost(sender, recipient.asOptional(), TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text))
30                         throw RedirectException(returnPage)
31                 }
32         }
33
34 }