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=0505220b1497ed6559b6f92a9b82c3bb3127d1e6;hb=419098bcd6215125408b29e60bd888e60979d37b;hpb=4c831fb948000bc1730ebcde73eeb62317f4ac54 diff --git a/src/main/java/net/pterodactylus/sone/web/LoginPage.java b/src/main/java/net/pterodactylus/sone/web/LoginPage.java index 0505220..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,20 @@ 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; /** * The login page manages logging the user in. @@ -34,6 +39,10 @@ import net.pterodactylus.util.template.Template; */ public class LoginPage extends SoneTemplatePage { + /** The logger. */ + @SuppressWarnings("unused") + private static final Logger logger = getLogger(LoginPage.class.getName()); + /** * Creates a new login page. * @@ -54,36 +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) { + if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) { + return false; + } + return getCurrentSone(toadletContext, false) == null; } }