1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.main.*
5 import net.pterodactylus.sone.utils.*
6 import net.pterodactylus.sone.web.*
7 import net.pterodactylus.sone.web.page.*
8 import net.pterodactylus.util.template.*
12 * The login page lets the user log in.
15 @TemplatePath("/templates/login.html")
16 @ToadletPath("login.html")
17 class LoginPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
18 SoneTemplatePage(webInterface, loaders, templateRenderer, pageTitleKey = "Page.Login.Title") {
20 override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
21 if (soneRequest.isPOST) {
22 val soneId = soneRequest.httpRequest.getPartAsStringFailsafe("sone-id", 43)
23 soneRequest.core.getLocalSone(soneId)?.let { sone ->
24 setCurrentSone(soneRequest.toadletContext, sone)
25 val target = soneRequest.httpRequest.getParam("target").emptyToNull ?: "index.html"
29 templateContext["sones"] = soneRequest.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR)
30 templateContext["identitiesWithoutSone"] = soneRequest.core.identityManager.allOwnIdentities.filterNot { "Sone" in it.contexts }.sortedBy { "${it.nickname}@${it.id}" }
33 override fun getRedirectTarget(request: FreenetRequest) =
34 getCurrentSone(request.toadletContext)?.let { "index.html" }
36 override fun isEnabled(soneRequest: SoneRequest) = when {
37 soneRequest.core.preferences.requireFullAccess && !soneRequest.toadletContext.isAllowedFullAccess -> false
38 else -> getCurrentSone(soneRequest.toadletContext, false) == null