X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FLoginPage.java;h=95443c8d916d9114400a13e3caa4f8888f83c801;hb=e14e8aff491d7a04e4e04ed9c38bcae630195655;hp=4965bbfd5d4668a467b0988501ad40b01cbfb320;hpb=7da3ac7e3aa5eabbbfccf7eb0549e94d48a44cf5;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 4965bbf..95443c8 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–2013 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,13 +17,23 @@ 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.web.page.Page.Request.Method; +import net.pterodactylus.sone.freenet.wot.OwnIdentity; +import net.pterodactylus.sone.web.page.FreenetRequest; +import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; + import freenet.clients.http.ToadletContext; +import com.google.common.base.Optional; + /** * The login page manages logging the user in. * @@ -31,6 +41,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,42 +54,54 @@ 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) { - Set localSones = webInterface.core().localSones(); - template.set("sones", localSones); - } - - /** - * {@inheritDoc} - */ - @Override - protected String getRedirectTarget(Request request) { + 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().getParam("sone-id"); - Sone selectedSone = null; - for (Sone sone : webInterface.core().localSones()) { - if (sone.getId().equals(soneId)) { - selectedSone = sone; - break; + String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone-id", 100); + Optional selectedSone = webInterface.getCore().getLocalSone(soneId); + if (selectedSone.isPresent()) { + setCurrentSone(request.getToadletContext(), selectedSone.get()); + String target = request.getHttpRequest().getParam("target"); + if ((target == null) || (target.length() == 0)) { + target = "index.html"; } - } - if (selectedSone != null) { - setCurrentSone(request.getToadletContext(), selectedSone); - return "index.html"; + throw new RedirectException(target); } } + List ownIdentitiesWithoutSone = CreateSonePage.getOwnIdentitiesWithoutSone(webInterface.getCore()); + templateContext.set("identitiesWithoutSone", ownIdentitiesWithoutSone); + } + + @Override + protected String getRedirectTarget(FreenetRequest request) { + if (getCurrentSone(request.getToadletContext(), false) != null) { + return "index.html"; + } return null; } + // + // SONETEMPLATEPAGE METHODS + // + + @Override + public boolean isEnabled(ToadletContext toadletContext) { + if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) { + return false; + } + return getCurrentSone(toadletContext, false) == null; + } + }