1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.utils.isPOST
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.FreenetRequest
7 import net.pterodactylus.util.template.Template
8 import net.pterodactylus.util.template.TemplateContext
9 import javax.inject.Inject
12 * Lets the user delete a post they made.
14 class DeletePostPage @Inject constructor(template: Template, webInterface: WebInterface):
15 LoggedInPage("deletePost.html", template, "Page.DeletePost.Title", webInterface) {
17 override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
18 if (freenetRequest.isPOST) {
19 val post = webInterface.core.getPost(freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)) ?: throw RedirectException("noPermission.html")
20 val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
21 if (!post.sone.isLocal) {
22 throw RedirectException("noPermission.html")
24 if (freenetRequest.httpRequest.isPartSet("confirmDelete")) {
25 webInterface.core.deletePost(post)
26 throw RedirectException(returnPage)
27 } else if (freenetRequest.httpRequest.isPartSet("abortDelete")) {
28 throw RedirectException(returnPage)
30 templateContext["post"] = post
31 templateContext["returnPage"] = returnPage
34 templateContext["post"] = webInterface.core.getPost(freenetRequest.httpRequest.getParam("post")) ?: throw RedirectException("noPermission.html")
35 templateContext["returnPage"] = freenetRequest.httpRequest.getParam("returnPage")