X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FDeletePostPage.kt;h=23963707c743d14ffa631c9e04f1d7d57b3711da;hp=21465d730bc87fde010c562597a7851e3d719c05;hb=aaf780d3c2a6f5ce47295786f3963c8b93f6a145;hpb=ffd92ca2374c0b2218e583d02e0bdd24b8c110ae diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt index 21465d7..2396370 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt @@ -1,36 +1,40 @@ package net.pterodactylus.sone.web.pages -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 net.pterodactylus.sone.data.* +import net.pterodactylus.sone.main.* +import net.pterodactylus.sone.utils.* +import net.pterodactylus.sone.web.* +import net.pterodactylus.sone.web.page.* +import net.pterodactylus.util.template.* +import javax.inject.* /** * Lets the user delete a post they made. */ -class DeletePostPage(template: Template, webInterface: WebInterface): - SoneTemplatePage("deletePost.html", template, "Page.DeletePost.Title", webInterface, true) { +@TemplatePath("/templates/deletePost.html") +@ToadletPath("deletePost.html") +class DeletePostPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + LoggedInPage("Page.DeletePost.Title", webInterface, loaders, templateRenderer) { - override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { - if (freenetRequest.isPOST) { - val post = webInterface.core.getPost(freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)).orNull() ?: throw RedirectException("noPermission.html") - val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) + override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { + if (soneRequest.isPOST) { + val post = soneRequest.core.getPost(soneRequest.httpRequest.getPartAsStringFailsafe("post", 36)) ?: redirectTo("noPermission.html") + val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) if (!post.sone.isLocal) { - throw RedirectException("noPermission.html") + redirectTo("noPermission.html") } - if (freenetRequest.httpRequest.isPartSet("confirmDelete")) { - webInterface.core.deletePost(post) - throw RedirectException(returnPage) - } else if (freenetRequest.httpRequest.isPartSet("abortDelete")) { - throw RedirectException(returnPage) + if (soneRequest.httpRequest.isPartSet("confirmDelete")) { + soneRequest.core.deletePost(post) + redirectTo(returnPage) + } else if (soneRequest.httpRequest.isPartSet("abortDelete")) { + redirectTo(returnPage) } templateContext["post"] = post templateContext["returnPage"] = returnPage return } - templateContext["post"] = webInterface.core.getPost(freenetRequest.httpRequest.getParam("post")).orNull() ?: throw RedirectException("noPermission.html") - templateContext["returnPage"] = freenetRequest.httpRequest.getParam("returnPage") + templateContext["post"] = soneRequest.core.getPost(soneRequest.httpRequest.getParam("post")) ?: redirectTo("noPermission.html") + templateContext["returnPage"] = soneRequest.httpRequest.getParam("returnPage") } }