projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Replace new page with Kotlin version
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
web
/
ajax
/
JsonPage.java
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
eee28ec
..
2f84d27
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java
@@
-27,7
+27,10
@@
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.annotation.Nonnull;
+
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.SessionProvider;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.web.page.FreenetPage;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.web.page.FreenetPage;
import net.pterodactylus.sone.web.page.FreenetRequest;
@@
-36,7
+39,6
@@
import net.pterodactylus.util.web.Page;
import net.pterodactylus.util.web.Response;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.pterodactylus.util.web.Response;
import com.fasterxml.jackson.databind.ObjectMapper;
-import freenet.clients.http.SessionManager.Session;
import freenet.clients.http.ToadletContext;
/**
import freenet.clients.http.ToadletContext;
/**
@@
-58,6
+60,7
@@
public abstract class JsonPage implements FreenetPage {
/** The Sone web interface. */
protected final WebInterface webInterface;
/** The Sone web interface. */
protected final WebInterface webInterface;
+ private final SessionProvider sessionProvider;
/**
* Creates a new JSON page at the given path.
/**
* Creates a new JSON page at the given path.
@@
-70,26
+73,19
@@
public abstract class JsonPage implements FreenetPage {
public JsonPage(String path, WebInterface webInterface) {
this.path = path;
this.webInterface = webInterface;
public JsonPage(String path, WebInterface webInterface) {
this.path = path;
this.webInterface = webInterface;
+ this.sessionProvider = webInterface;
}
//
// ACCESSORS
//
}
//
// ACCESSORS
//
- /**
- * Returns the currently logged in Sone.
- *
- * @param toadletContext
- * The toadlet context
- * @return The currently logged in Sone, or {@code null} if no Sone is
- * currently logged in
- */
protected Sone getCurrentSone(ToadletContext toadletContext) {
protected Sone getCurrentSone(ToadletContext toadletContext) {
- return
webInterface.getCurrentSoneCreatingSession(toadletContext
);
+ return
sessionProvider.getCurrentSone(toadletContext, true
);
}
}
- protected Sone getCurrentSone
WithoutCreatingSession(ToadletContext toadletContext
) {
- return
webInterface.getCurrentSoneWithoutCreatingSession(toadletContext
);
+ protected Sone getCurrentSone
(ToadletContext toadletContext, boolean createSession
) {
+ return
sessionProvider.getCurrentSone(toadletContext, createSession
);
}
//
}
//
@@
-138,6
+134,7
@@
public abstract class JsonPage implements FreenetPage {
*
* @return A reply signaling success
*/
*
* @return A reply signaling success
*/
+ @Nonnull
protected static JsonReturnObject createSuccessJsonObject() {
return new JsonReturnObject(true);
}
protected static JsonReturnObject createSuccessJsonObject() {
return new JsonReturnObject(true);
}
@@
-149,6
+146,7
@@
public abstract class JsonPage implements FreenetPage {
* The error that has occured
* @return The JSON object, signalling failure and the error code
*/
* The error that has occured
* @return The JSON object, signalling failure and the error code
*/
+ @Nonnull
protected static JsonReturnObject createErrorJsonObject(String error) {
return new JsonErrorReturnObject(error);
}
protected static JsonReturnObject createErrorJsonObject(String error) {
return new JsonErrorReturnObject(error);
}
@@
-188,7
+186,7
@@
public abstract class JsonPage implements FreenetPage {
}
}
if (requiresLogin()) {
}
}
if (requiresLogin()) {
- if (getCurrentSone
WithoutCreatingSession(request.getToadletContext()
) == null) {
+ if (getCurrentSone
(request.getToadletContext(), false
) == null) {
return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(objectMapper.writeValueAsString(new JsonErrorReturnObject("auth-required")));
}
}
return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(objectMapper.writeValueAsString(new JsonErrorReturnObject("auth-required")));
}
}