Replace like page with Kotlin version
[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.pages.SoneTemplatePage
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
10 /**
11  * Page that lets the user distrust another Sone. This will assign a
12  * configurable (negative) amount of trust to an identity.
13  *
14  * @see net.pterodactylus.sone.core.Core#distrustSone(Sone, Sone)
15  */
16 class DistrustPage(template: Template, webInterface: WebInterface):
17                 SoneTemplatePage("distrust.html", template, "Page.Distrust.Title", webInterface, true) {
18
19         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
20                 if (request.isPOST) {
21                         val sone = webInterface.core.getSone(request.httpRequest.getPartAsStringFailsafe("sone", 44)).orNull()
22                         sone?.run { webInterface.core.distrustSone(getCurrentSone(request.toadletContext), this) }
23                         throw RedirectException(request.httpRequest.getPartAsStringFailsafe("returnPage", 256))
24                 }
25         }
26
27 }