🔀 Merge branch 'release/v82'
[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.*
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 @ToadletPath("unlockSone.ajax")
12 class UnlockSoneAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(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 }