X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FLoginPage.java;h=4b38a07cfa97bcbbb095760cb582c7425bcb1dc3;hp=c859cf607ed75e5764916adf4caea42ed2db37fb;hb=419098bcd6215125408b29e60bd888e60979d37b;hpb=b2222ffddcd6ece5daa677619e9f14dc704d1ce4 diff --git a/src/main/java/net/pterodactylus/sone/web/LoginPage.java b/src/main/java/net/pterodactylus/sone/web/LoginPage.java index c859cf6..4b38a07 100644 --- a/src/main/java/net/pterodactylus/sone/web/LoginPage.java +++ b/src/main/java/net/pterodactylus/sone/web/LoginPage.java @@ -1,5 +1,5 @@ /* - * FreenetSone - LoginPage.java - Copyright © 2010 David Roden + * Sone - LoginPage.java - Copyright © 2010–2015 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,15 +17,19 @@ package net.pterodactylus.sone.web; +import static java.util.logging.Logger.getLogger; + import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.List; +import java.util.logging.Logger; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.template.SoneAccessor; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.freenet.wot.OwnIdentity; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; import freenet.clients.http.ToadletContext; /** @@ -35,6 +39,10 @@ import freenet.clients.http.ToadletContext; */ public class LoginPage extends SoneTemplatePage { + /** The logger. */ + @SuppressWarnings("unused") + private static final Logger logger = getLogger(LoginPage.class.getName()); + /** * Creates a new login page. * @@ -44,7 +52,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); } // @@ -55,44 +63,52 @@ public class LoginPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); - List localSones = new ArrayList(webInterface.core().getSones()); - Collections.sort(localSones, new Comparator() { - - @Override - public int compare(Sone leftSone, Sone rightSone) { - int diff = SoneAccessor.getNiceName(leftSone).compareToIgnoreCase(SoneAccessor.getNiceName(rightSone)); - if (diff != 0) { - return diff; - } - return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightSone.getTime() - leftSone.getTime())); - } - - }); - template.set("sones", localSones); + protected void processTemplate(FreenetRequest 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().getSones()) { - if (sone.getId().equals(soneId)) { - selectedSone = sone; - break; - } - } + Sone selectedSone = webInterface.getCore().getLocalSone(soneId); 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(FreenetRequest 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; + if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) { + return false; + } + return getCurrentSone(toadletContext, false) == null; } }