0c44b3b5a23d45bbe502371417293c7c7e59ae77
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / UnlockSonePage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.main.*
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.*
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
10 import javax.inject.Inject
11
12 /**
13  * This page lets the user unlock a [net.pterodactylus.sone.data.Sone] to allow its insertion.
14  */
15 class UnlockSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
16                 SoneTemplatePage("unlockSone.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.UnlockSone.Title") {
17
18         override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
19                 if (soneRequest.isPOST) {
20                         soneRequest.parameters["sone", 44]
21                                         .let(soneRequest.core::getLocalSone)
22                                         ?.also(soneRequest.core::unlockSone)
23                         throw RedirectException(soneRequest.parameters["returnPage", 256])
24                 }
25         }
26
27 }