Add base JSON page that requires a logged-in user
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ajax / UnfollowSoneAjaxPage.java
index 58af936..28ffbf2 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.sone.web.ajax;
 
+import javax.annotation.Nonnull;
+
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
@@ -26,7 +28,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class UnfollowSoneAjaxPage extends JsonPage {
+public class UnfollowSoneAjaxPage extends LoggedInJsonPage {
 
        /**
         * Creates a new “unfollow Sone” AJAX page.
@@ -41,16 +43,13 @@ public class UnfollowSoneAjaxPage extends JsonPage {
        /**
         * {@inheritDoc}
         */
+       @Nonnull
        @Override
-       protected JsonReturnObject createJsonObject(FreenetRequest request) {
+       protected JsonReturnObject createJsonObject(@Nonnull Sone currentSone, @Nonnull FreenetRequest request) {
                String soneId = request.getHttpRequest().getParam("sone");
                if (!webInterface.getCore().getSone(soneId).isPresent()) {
                        return createErrorJsonObject("invalid-sone-id");
                }
-               Sone currentSone = getCurrentSone(request.getToadletContext());
-               if (currentSone == null) {
-                       return createErrorJsonObject("auth-required");
-               }
                webInterface.getCore().unfollowSone(currentSone, soneId);
                return createSuccessJsonObject();
        }