X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FCreateSonePage.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FCreateSonePage.kt;h=b2056c2cc5189ee35f949bbae6f2d7eb210e7da8;hp=efa6f1dc8a346ab928aefdb36274bf0ff957f6ee;hb=03cec6a6772c2d836d94864adddaf544cbe9d72f;hpb=6f1f26e3998cfef155b0cf59152827accea70d30 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 efa6f1d..b2056c2 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt @@ -1,45 +1,47 @@ 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.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 net.pterodactylus.sone.data.* +import net.pterodactylus.sone.main.* +import net.pterodactylus.sone.utils.* +import net.pterodactylus.sone.web.* +import net.pterodactylus.sone.web.page.* +import net.pterodactylus.util.template.* +import java.util.logging.* +import javax.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) { +@MenuName("CreateSone") +@TemplatePath("/templates/createSone.html") +@ToadletPath("createSone.html") +class CreateSonePage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + SoneTemplatePage(webInterface, loaders, templateRenderer, pageTitleKey = "Page.CreateSone.Title") { private val logger = Logger.getLogger(CreateSonePage::class.java.name) - 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 (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) + override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { + templateContext["sones"] = soneRequest.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR) + templateContext["identitiesWithoutSone"] = soneRequest.core.identityManager.allOwnIdentities.filterNot { "Sone" in it.contexts }.sortedBy { "${it.nickname}@${it.id}".toLowerCase() } + if (soneRequest.isPOST) { + val identity = soneRequest.httpRequest.getPartAsStringFailsafe("identity", 43) + soneRequest.core.identityManager.allOwnIdentities.firstOrNull { it.id == identity }?.let { ownIdentity -> + val sone = soneRequest.core.createSone(ownIdentity) if (sone == null) { logger.log(Level.SEVERE, "Could not create Sone for OwnIdentity: $ownIdentity") } - setCurrentSone(freenetRequest.toadletContext, sone) + setCurrentSone(soneRequest.toadletContext, sone) throw RedirectException("index.html") } templateContext["errorNoIdentity"] = true } } - override fun isEnabled(toadletContext: ToadletContext) = - if (webInterface.core.preferences.isRequireFullAccess && !toadletContext.isAllowedFullAccess) { + override fun isEnabled(soneRequest: SoneRequest) = + if (soneRequest.core.preferences.requireFullAccess && !soneRequest.toadletContext.isAllowedFullAccess) { false } else { - (getCurrentSone(toadletContext) == null) || (webInterface.core.localSones.size == 1) + (getCurrentSone(soneRequest.toadletContext) == null) || (soneRequest.core.localSones.size == 1) } }