Replace unlock Sone page with Kotlin version
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / UnlockSonePage.kt
diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt
new file mode 100644 (file)
index 0000000..7ed2418
--- /dev/null
@@ -0,0 +1,25 @@
+package net.pterodactylus.sone.web.pages
+
+import net.pterodactylus.sone.utils.isPOST
+import net.pterodactylus.sone.utils.parameters
+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
+
+/**
+ * This page lets the user unlock a [net.pterodactylus.sone.data.Sone] to allow its insertion.
+ */
+class UnlockSonePage(template: Template, webInterface: WebInterface):
+               SoneTemplatePage("unlockSone.html", template, "Page.UnlockSone.Title", webInterface, false) {
+
+       override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+               if (request.isPOST) {
+                       request.parameters["sone", 44]
+                                       .let(webInterface.core::getLocalSone)
+                                       ?.also(webInterface.core::unlockSone)
+                       throw RedirectException(request.parameters["returnPage", 256])
+               }
+       }
+
+}