X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FDeletePostPage.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FDeletePostPage.kt;h=99ccb3a88ddeee83d277890f2e5d644f00722eee;hp=0000000000000000000000000000000000000000;hb=de7568a82eb4150bf6d2b0553841b7b69f84c968;hpb=9acbc5bdec4ccb752e0856a501568b0bb6161579 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt new file mode 100644 index 0000000..99ccb3a --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt @@ -0,0 +1,34 @@ +package net.pterodactylus.sone.web.pages + +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 +import net.pterodactylus.util.template.TemplateContext + +/** + * Lets the user delete a post they made. + */ +class DeletePostPage(template: Template, webInterface: WebInterface): + SoneTemplatePage("deletePost.html", template, "Page.DeletePost.Title", webInterface, true) { + + override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { + val post = webInterface.core.getPost(request.httpRequest.getPartAsStringFailsafe("post", 36)).orNull() ?: throw RedirectException("noPermission.html") + val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256) + if (request.isPOST) { + if (!post.sone.isLocal) { + throw RedirectException("noPermission.html") + } + if (request.httpRequest.isPartSet("confirmDelete")) { + webInterface.core.deletePost(post) + throw RedirectException(returnPage) + } else if (request.httpRequest.isPartSet("abortDelete")) { + throw RedirectException(returnPage) + } + } + templateContext["post"] = post + templateContext["returnPage"] = returnPage + } + +}