efa70f100c267540a6f2c80870a72e2e3be87950
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / ajax / UnlockSoneAjaxPage.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.utils.parameters
4 import net.pterodactylus.sone.web.WebInterface
5 import net.pterodactylus.sone.web.page.FreenetRequest
6 import javax.inject.Inject
7
8 /**
9  * Lets the user [unlock][net.pterodactylus.sone.core.Core.unlockSone] a [Sone][net.pterodactylus.sone.data.Sone].
10  */
11 class UnlockSoneAjaxPage @Inject constructor(webInterface: WebInterface) :
12                 JsonPage("unlockSone.ajax", webInterface) {
13
14         override val requiresLogin = false
15
16         override fun createJsonObject(request: FreenetRequest) =
17                         request.parameters["sone"]
18                                         ?.let(core::getLocalSone)
19                                         ?.also(core::unlockSone)
20                                         ?.also { core.touchConfiguration() }
21                                         ?.let { createSuccessJsonObject() }
22                                         ?: createErrorJsonObject("invalid-sone-id")
23
24 }