Add page that always requires a logged-in user
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / TrustPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.utils.isPOST
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
10
11 /**
12  * Page that lets the user trust another Sone. This will assign a configurable
13  * amount of trust to an identity.
14  */
15 class TrustPage(template: Template, webInterface: WebInterface):
16                 LoggedInPage("trust.html", template, "Page.Trust.Title", webInterface) {
17
18         override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
19                 if (freenetRequest.isPOST) {
20                                 webInterface.core.getSone(freenetRequest.parameters["sone"]!!)?.let { sone ->
21                                         webInterface.core.trustSone(currentSone, sone)
22                                 }
23                         throw RedirectException(freenetRequest.parameters["returnPage", 256])
24                 }
25         }
26
27 }