X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FLoginPage.java;h=eaa83517bc902225f741ff0c45aa32ad94605a1c;hb=c8fbf072a53cb60c54c22ab14511e24f36b92d88;hp=7e99b32e3e0fab31f65339dec6f1abd62962d9bc;hpb=8276173b917c67f253c59f5ddf99b4deb155a870;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/LoginPage.java b/src/main/java/net/pterodactylus/sone/web/LoginPage.java index 7e99b32..eaa8351 100644 --- a/src/main/java/net/pterodactylus/sone/web/LoginPage.java +++ b/src/main/java/net/pterodactylus/sone/web/LoginPage.java @@ -17,11 +17,17 @@ package net.pterodactylus.sone.web; -import java.util.Set; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.logging.Logger; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.freenet.wot.OwnIdentity; import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; import freenet.clients.http.ToadletContext; /** @@ -31,6 +37,10 @@ import freenet.clients.http.ToadletContext; */ public class LoginPage extends SoneTemplatePage { + /** The logger. */ + @SuppressWarnings("unused") + private static final Logger logger = Logging.getLogger(LoginPage.class); + /** * Creates a new login page. * @@ -40,7 +50,7 @@ public class LoginPage extends SoneTemplatePage { * The Sone web interface */ public LoginPage(Template template, WebInterface webInterface) { - super("login.html", template, "Page.Login.Title", webInterface); + super("login.html", template, "Page.Login.Title", webInterface, false); } // @@ -51,31 +61,49 @@ public class LoginPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - Set localSones = webInterface.core().localSones(); - template.set("sones", localSones); + protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + super.processTemplate(request, templateContext); + /* get all own identities. */ + List localSones = new ArrayList(webInterface.getCore().getLocalSones()); + Collections.sort(localSones, Sone.NICE_NAME_COMPARATOR); + templateContext.set("sones", localSones); if (request.getMethod() == Method.POST) { String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone-id", 100); - Sone selectedSone = null; - for (Sone sone : webInterface.core().localSones()) { - if (sone.getId().equals(soneId)) { - selectedSone = sone; - break; - } - } + Sone selectedSone = webInterface.getCore().getLocalSone(soneId, false); if (selectedSone != null) { setCurrentSone(request.getToadletContext(), selectedSone); - throw new RedirectException("index.html"); + String target = request.getHttpRequest().getParam("target"); + if ((target == null) || (target.length() == 0)) { + target = "index.html"; + } + throw new RedirectException(target); } } + List ownIdentitiesWithoutSone = CreateSonePage.getOwnIdentitiesWithoutSone(webInterface.getCore()); + templateContext.set("identitiesWithoutSone", ownIdentitiesWithoutSone); + } + + /** + * {@inheritDoc} + */ + @Override + protected String getRedirectTarget(Request request) { + if (getCurrentSone(request.getToadletContext(), false) != null) { + return "index.html"; + } + return null; } + // + // SONETEMPLATEPAGE METHODS + // + /** * {@inheritDoc} */ @Override public boolean isEnabled(ToadletContext toadletContext) { - return getCurrentSone(toadletContext) == null; + return getCurrentSone(toadletContext, false) == null; } }