X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FLoginPage.java;h=6c3e5c59a561b412e19d6511ebe9639028bbc08f;hb=c5e96f331ebec74bfa4da5ec7d4c7c888321480d;hp=df06c87c4f4bfc528e38b1e52543dfdc48700833;hpb=d4c0238c0e479a3d08390de0e71c1d29beda00e7;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 df06c87..6c3e5c5 100644 --- a/src/main/java/net/pterodactylus/sone/web/LoginPage.java +++ b/src/main/java/net/pterodactylus/sone/web/LoginPage.java @@ -17,7 +17,17 @@ package net.pterodactylus.sone.web; +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 freenet.clients.http.ToadletContext; /** * The login page manages logging the user in. @@ -26,6 +36,10 @@ import net.pterodactylus.util.template.Template; */ public class LoginPage extends SoneTemplatePage { + /** The logger. */ + @SuppressWarnings("unused") + private static final Logger logger = Logging.getLogger(LoginPage.class); + /** * Creates a new login page. * @@ -35,7 +49,45 @@ 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); + } + + // + // TEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected void processTemplate(Request request, Template template) throws RedirectException { + super.processTemplate(request, template); + /* get all own identities. */ + List localSones = new ArrayList(webInterface.getCore().getLocalSones()); + Collections.sort(localSones, Sone.NICE_NAME_COMPARATOR); + template.set("sones", localSones); + if (request.getMethod() == Method.POST) { + String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone-id", 100); + Sone selectedSone = webInterface.getCore().getLocalSone(soneId); + if (selectedSone != null) { + setCurrentSone(request.getToadletContext(), selectedSone); + throw new RedirectException("index.html"); + } + } + List ownIdentitiesWithoutSone = CreateSonePage.getOwnIdentitiesWithoutSone(webInterface.getCore()); + template.set("identitiesWithoutSone", ownIdentitiesWithoutSone); + } + + // + // SONETEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public boolean isEnabled(ToadletContext toadletContext) { + return getCurrentSone(toadletContext) == null; } }