X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FJsonPage.java;h=8e7d27ed4e92cbddab576ebd815532dc682b9c25;hb=c9dfdab1c3d57ebbce513ca437b52690a9f086ab;hp=fb0a5bb050598cc7d3670797c73a3b4c07f61b6e;hpb=a1b807f1cd3606c38cefe955172d7c5b297c6e3a;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java index fb0a5bb..8e7d27e 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java @@ -85,9 +85,9 @@ public abstract class JsonPage implements Page { */ protected Session getCurrentSession(ToadletContext toadletContenxt, boolean create) { try { - Session session = webInterface.sessionManager().useSession(toadletContenxt); + Session session = webInterface.getSessionManager().useSession(toadletContenxt); if (create && (session == null)) { - session = webInterface.sessionManager().createSession(UUID.randomUUID().toString(), toadletContenxt); + session = webInterface.getSessionManager().createSession(UUID.randomUUID().toString(), toadletContenxt); } return session; } catch (freenet.clients.http.RedirectException re1) { @@ -112,12 +112,7 @@ public abstract class JsonPage implements Page { if (soneId == null) { return null; } - for (Sone sone : webInterface.core().getSones()) { - if (sone.getId().equals(soneId)) { - return sone; - } - } - return null; + return webInterface.getCore().getLocalSone(soneId, false); } // @@ -146,6 +141,21 @@ public abstract class JsonPage implements Page { } // + // PROTECTED METHODS + // + + /** + * Creates an error reply. + * + * @param error + * The error that has occured + * @return The JSON object, signalling failure and the error code + */ + protected JsonObject createErrorJsonObject(String error) { + return new JsonObject().put("success", false).put("error", error); + } + + // // PAGE METHODS // @@ -164,8 +174,8 @@ public abstract class JsonPage implements Page { public Response handleRequest(Request request) { if (needsFormPassword()) { String formPassword = request.getHttpRequest().getParam("formPassword"); - if (!webInterface.formPassword().equals(formPassword)) { - return new Response(401, "Not authorized", "application/json", JsonUtils.format(new JsonObject().put("success", false))); + if (!webInterface.getFormPassword().equals(formPassword)) { + return new Response(401, "Not authorized", "application/json", JsonUtils.format(new JsonObject().put("success", false).put("error", "auth-required"))); } } JsonObject jsonObject = createJsonObject(request);