X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FCreateSonePage.kt;h=a0fe7cb0a509127199da175aebd0ce561e7483e0;hb=fc8e9ea5c978d2f5a00894e093364ae62f18934b;hp=f864b734d657f0802ed2e0cd574a3a55c9a4e5ed;hpb=de7568a82eb4150bf6d2b0553841b7b69f84c968;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt index f864b73..a0fe7cb 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt @@ -3,33 +3,33 @@ package net.pterodactylus.sone.web.pages import freenet.clients.http.ToadletContext import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.isPOST -import net.pterodactylus.sone.web.pages.SoneTemplatePage 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 import java.util.logging.Level import java.util.logging.Logger +import javax.inject.Inject /** * The “create Sone” page lets the user create a new Sone. */ -class CreateSonePage(template: Template, webInterface: WebInterface): - SoneTemplatePage("createSone.html", template, "Page.CreateSone.Title", webInterface, false) { +class CreateSonePage @Inject constructor(template: Template, webInterface: WebInterface): + SoneTemplatePage("createSone.html", webInterface, template, "Page.CreateSone.Title") { private val logger = Logger.getLogger(CreateSonePage::class.java.name) - override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { + override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { templateContext["sones"] = webInterface.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR) templateContext["identitiesWithoutSone"] = webInterface.core.identityManager.allOwnIdentities.filterNot { "Sone" in it.contexts }.sortedBy { "${it.nickname}@${it.id}".toLowerCase() } - if (request.isPOST) { - val identity = request.httpRequest.getPartAsStringFailsafe("identity", 43) + if (freenetRequest.isPOST) { + val identity = freenetRequest.httpRequest.getPartAsStringFailsafe("identity", 43) webInterface.core.identityManager.allOwnIdentities.firstOrNull { it.id == identity }?.let { ownIdentity -> val sone = webInterface.core.createSone(ownIdentity) if (sone == null) { logger.log(Level.SEVERE, "Could not create Sone for OwnIdentity: $ownIdentity") } - setCurrentSone(request.toadletContext, sone) + setCurrentSone(freenetRequest.toadletContext, sone) throw RedirectException("index.html") } templateContext["errorNoIdentity"] = true @@ -37,7 +37,7 @@ class CreateSonePage(template: Template, webInterface: WebInterface): } override fun isEnabled(toadletContext: ToadletContext) = - if (webInterface.core.preferences.isRequireFullAccess && !toadletContext.isAllowedFullAccess) { + if (webInterface.core.preferences.requireFullAccess && !toadletContext.isAllowedFullAccess) { false } else { (getCurrentSone(toadletContext) == null) || (webInterface.core.localSones.size == 1)