X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FSoneTemplatePage.java;h=a6a87df9ca7fe202589a1e5145786e22d0da52ae;hb=5bcd2637c93dda90b9a1fdb785c5f4b08a04f9e0;hp=ccd0d053f440682f4c6f4d75d8b471a00194f6c3;hpb=316b9c2b3d16792975434644ae39a9b1814f32c4;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index ccd0d05..a6a87df 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -17,15 +17,20 @@ package net.pterodactylus.sone.web; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.Arrays; import java.util.Collection; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.sone.web.page.Page; import net.pterodactylus.sone.web.page.TemplatePage; import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; import freenet.clients.http.SessionManager.Session; import freenet.clients.http.ToadletContext; +import freenet.support.api.HTTPRequest; /** * Base page for the Freetalk web interface. @@ -72,10 +77,10 @@ public class SoneTemplatePage extends TemplatePage { * Whether this page requires a login */ public SoneTemplatePage(String path, Template template, String pageTitleKey, WebInterface webInterface, boolean requireLogin) { - super(path, template, webInterface.getL10n(), pageTitleKey, "noPermission.html"); + super(path, webInterface.getTemplateContextFactory(), template, webInterface.getL10n(), pageTitleKey, "noPermission.html"); this.webInterface = webInterface; this.requireLogin = requireLogin; - template.set("webInterface", webInterface); + template.getInitialContext().set("webInterface", webInterface); } // @@ -184,10 +189,16 @@ public class SoneTemplatePage extends TemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); - template.set("currentSone", getCurrentSone(request.getToadletContext())); - template.set("request", request); + protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + super.processTemplate(request, templateContext); + templateContext.set("currentSone", getCurrentSone(request.getToadletContext(), false)); + templateContext.set("localSones", webInterface.getCore().getLocalSones()); + templateContext.set("request", request); + templateContext.set("currentVersion", SonePlugin.VERSION); + templateContext.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion()); + templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition()); + templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion()); + templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate()); } /** @@ -195,8 +206,27 @@ public class SoneTemplatePage extends TemplatePage { */ @Override protected String getRedirectTarget(Page.Request request) { - if (requiresLogin() && (getCurrentSone(request.getToadletContext()) == null)) { - return "login.html"; + if (requiresLogin() && (getCurrentSone(request.getToadletContext(), false) == null)) { + HTTPRequest httpRequest = request.getHttpRequest(); + String originalUrl = httpRequest.getPath(); + if (httpRequest.hasParameters()) { + StringBuilder requestParameters = new StringBuilder(); + for (String parameterName : httpRequest.getParameterNames()) { + if (requestParameters.length() > 0) { + requestParameters.append('&'); + } + String[] parameterValues = httpRequest.getMultipleParam(parameterName); + for (String parameterValue : parameterValues) { + try { + requestParameters.append(URLEncoder.encode(parameterName, "UTF-8")).append('=').append(URLEncoder.encode(parameterValue, "UTF-8")); + } catch (UnsupportedEncodingException uee1) { + /* A JVM without UTF-8? I don’t think so. */ + } + } + } + originalUrl += "?" + requestParameters.toString(); + } + return "login.html?target=" + originalUrl; } return null; }