package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone 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 /** * Lets the user delete a post they made. */ class DeletePostPage @Inject constructor(template: Template, webInterface: WebInterface): LoggedInPage("deletePost.html", template, "Page.DeletePost.Title", webInterface) { override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) { if (freenetRequest.isPOST) { val post = webInterface.core.getPost(freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)) ?: throw RedirectException("noPermission.html") val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) if (!post.sone.isLocal) { throw RedirectException("noPermission.html") } if (freenetRequest.httpRequest.isPartSet("confirmDelete")) { webInterface.core.deletePost(post) throw RedirectException(returnPage) } else if (freenetRequest.httpRequest.isPartSet("abortDelete")) { throw RedirectException(returnPage) } templateContext["post"] = post templateContext["returnPage"] = returnPage return } templateContext["post"] = webInterface.core.getPost(freenetRequest.httpRequest.getParam("post")) ?: throw RedirectException("noPermission.html") templateContext["returnPage"] = freenetRequest.httpRequest.getParam("returnPage") } }