X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FCreatePostPage.kt;h=8a1268e9deb32e0f9cd3c069840e2e3715ac9b53;hb=9bb01bc8fe281e6748ebd744ade8945bee841213;hp=30a1c311826cd4978c82179257b9692205f185bf;hpb=3cb0e2c78bb37f2d70ecde92ad4fcf642de788a3;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 30a1c31..8a1268e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt @@ -1,19 +1,22 @@ 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.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext +import javax.inject.Inject /** * This page lets the user create a new [Post]. */ -class CreatePostPage(template: Template, webInterface: WebInterface): - SoneTemplatePage("createPost.html", template, "Page.CreatePost.Title", webInterface, true) { +class CreatePostPage @Inject constructor(template: Template, webInterface: WebInterface): + LoggedInPage("createPost.html", template, "Page.CreatePost.Title", webInterface) { - override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { + override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) { val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) templateContext["returnPage"] = returnPage if (freenetRequest.isPOST) { @@ -22,9 +25,9 @@ class CreatePostPage(template: Template, webInterface: WebInterface): templateContext["errorTextEmpty"] = true return } - val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(freenetRequest.toadletContext) + 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, TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text)) + webInterface.core.createPost(sender, recipient.asOptional(), TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text)) throw RedirectException(returnPage) } }