Use method from JsonPage
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DistrustPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.utils.isPOST
4 import net.pterodactylus.sone.web.WebInterface
5 import net.pterodactylus.sone.web.page.FreenetRequest
6 import net.pterodactylus.util.template.Template
7 import net.pterodactylus.util.template.TemplateContext
8
9 /**
10  * Page that lets the user distrust another Sone. This will assign a
11  * configurable (negative) amount of trust to an identity.
12  *
13  * @see net.pterodactylus.sone.core.Core#distrustSone(Sone, Sone)
14  */
15 class DistrustPage(template: Template, webInterface: WebInterface):
16                 SoneTemplatePage("distrust.html", template, "Page.Distrust.Title", webInterface, true) {
17
18         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
19                 if (request.isPOST) {
20                         val sone = webInterface.core.getSone(request.httpRequest.getPartAsStringFailsafe("sone", 44)).orNull()
21                         sone?.run { webInterface.core.distrustSone(getCurrentSone(request.toadletContext), this) }
22                         throw RedirectException(request.httpRequest.getPartAsStringFailsafe("returnPage", 256))
23                 }
24         }
25
26 }