72abb0e785ed0d98b79796fcb25318166892fd6d
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / LockSonePage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.main.*
4 import net.pterodactylus.sone.utils.*
5 import net.pterodactylus.sone.web.*
6 import net.pterodactylus.sone.web.page.*
7 import net.pterodactylus.util.template.*
8 import javax.inject.*
9
10 /**
11  * This page lets the user lock a [net.pterodactylus.sone.data.Sone] to prevent it from being inserted.
12  */
13 @ToadletPath("lockSone.html")
14 class LockSonePage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
15                 SoneTemplatePage("lockSone.html", webInterface, loaders, templateRenderer, pageTitleKey = "Page.LockSone.Title") {
16
17         override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
18                 soneRequest.parameters["returnPage", 256]!!.let { returnPage ->
19                         soneRequest.parameters["sone", 44]!!
20                                         .let { soneRequest.core.getLocalSone(it) }
21                                         ?.let { soneRequest.core.lockSone(it) }
22                         throw RedirectException(returnPage)
23                 }
24         }
25
26 }