X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FCreatePostPage.kt;h=31896f75605a709f3146b1108da8ca544b15b222;hb=74cbe983cd38da24847e6247ac595cb70d8e115b;hp=6e39d49f85170e07be55fc385ab0428fbec95470;hpb=de7568a82eb4150bf6d2b0553841b7b69f84c968;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt index 6e39d49..31896f7 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt @@ -1,8 +1,9 @@ package net.pterodactylus.sone.web.pages +import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.text.TextFilter +import net.pterodactylus.sone.utils.asOptional import net.pterodactylus.sone.utils.isPOST -import net.pterodactylus.sone.web.pages.SoneTemplatePage import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template @@ -12,20 +13,20 @@ import net.pterodactylus.util.template.TemplateContext * This page lets the user create a new [Post]. */ class CreatePostPage(template: Template, webInterface: WebInterface): - SoneTemplatePage("createPost.html", template, "Page.CreatePost.Title", webInterface, true) { + LoggedInPage("createPost.html", template, "Page.CreatePost.Title", webInterface) { - override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256) + override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) { + val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) templateContext["returnPage"] = returnPage - if (request.isPOST) { - val text = request.httpRequest.getPartAsStringFailsafe("text", 65536).trim() + if (freenetRequest.isPOST) { + val text = freenetRequest.httpRequest.getPartAsStringFailsafe("text", 65536).trim() if (text == "") { templateContext["errorTextEmpty"] = true return } - val sender = webInterface.core.getLocalSone(request.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(request.toadletContext) - val recipient = webInterface.core.getSone(request.httpRequest.getPartAsStringFailsafe("recipient", 43)) - webInterface.core.createPost(sender, recipient, TextFilter.filter(request.httpRequest.getHeader("Host"), text)) + val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone + val recipient = webInterface.core.getSone(freenetRequest.httpRequest.getPartAsStringFailsafe("recipient", 43)) + webInterface.core.createPost(sender, recipient.asOptional(), TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text)) throw RedirectException(returnPage) } }