1 package net.pterodactylus.sone.web.pages
3 import freenet.clients.http.ToadletContext
4 import net.pterodactylus.sone.data.Sone
5 import net.pterodactylus.sone.utils.emptyToNull
6 import net.pterodactylus.sone.utils.isPOST
7 import net.pterodactylus.sone.web.WebInterface
8 import net.pterodactylus.sone.web.page.FreenetRequest
9 import net.pterodactylus.util.template.Template
10 import net.pterodactylus.util.template.TemplateContext
13 * The login page lets the user log in.
15 class LoginPage(template: Template, webInterface: WebInterface):
16 SoneTemplatePage("login.html", template, "Page.Login.Title", webInterface) {
18 override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
20 val soneId = request.httpRequest.getPartAsStringFailsafe("sone-id", 43)
21 webInterface.core.getLocalSone(soneId)?.let { sone ->
22 setCurrentSone(request.toadletContext, sone)
23 val target = request.httpRequest.getParam("target").emptyToNull ?: "index.html"
24 throw RedirectException(target)
27 templateContext["sones"] = webInterface.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR)
28 templateContext["identitiesWithoutSone"] = webInterface.core.identityManager.allOwnIdentities.filterNot { "Sone" in it.contexts }.sortedBy { "${it.nickname}@${it.id}" }
31 override public fun getRedirectTarget(request: FreenetRequest) =
32 getCurrentSone(request.toadletContext)?.let { "index.html" }
34 override fun isEnabled(toadletContext: ToadletContext) = when {
35 webInterface.core.preferences.isRequireFullAccess && !toadletContext.isAllowedFullAccess -> false
36 else -> getCurrentSone(toadletContext, false) == null