*/
@Override
protected JsonReturnObject createJsonObject(FreenetRequest request) {
- Sone currentSone = getCurrentSoneWithoutCreatingSession(request.getToadletContext());
+ Sone currentSone = getCurrentSone(request.getToadletContext(), false);
List<Notification> notifications = new ArrayList<Notification>(webInterface.getNotifications(currentSone));
Collections.sort(notifications, Notification.CREATED_TIME_SORTER);
ArrayNode jsonNotifications = new ArrayNode(instance);
import javax.annotation.Nonnull;
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.util.web.Response;
import com.fasterxml.jackson.databind.ObjectMapper;
-import freenet.clients.http.SessionManager.Session;
import freenet.clients.http.ToadletContext;
/**
/** The Sone web interface. */
protected final WebInterface webInterface;
+ private final SessionProvider sessionProvider;
/**
* Creates a new JSON page at the given path.
public JsonPage(String path, WebInterface webInterface) {
this.path = path;
this.webInterface = webInterface;
+ this.sessionProvider = webInterface;
}
//
// 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) {
- return webInterface.getCurrentSoneCreatingSession(toadletContext);
+ return sessionProvider.getCurrentSone(toadletContext, true);
}
- protected Sone getCurrentSoneWithoutCreatingSession(ToadletContext toadletContext) {
- return webInterface.getCurrentSoneWithoutCreatingSession(toadletContext);
+ protected Sone getCurrentSone(ToadletContext toadletContext, boolean createSession) {
+ return sessionProvider.getCurrentSone(toadletContext, createSession);
}
//
}
}
if (requiresLogin()) {
- if (getCurrentSoneWithoutCreatingSession(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")));
}
}