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