X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FFollowSoneAjaxPage.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FFollowSoneAjaxPage.java;h=5b4fdc2a47fb81aa480f3529e57fb33af3dcfd60;hb=47df88512f5288d6a1f5f268cdf787bb4bf169c7;hp=0000000000000000000000000000000000000000;hpb=08a2857c3afa6c39464fd710d4ddd55cf7c19bca;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java new file mode 100644 index 0000000..5b4fdc2 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java @@ -0,0 +1,59 @@ +/* + * Sone - FollowSoneAjaxPage.java - Copyright © 2010 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.web.ajax; + +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.util.json.JsonObject; + +/** + * AJAX page that lets a Sone follow another Sone. + * + * @author David ‘Bombe’ Roden + */ +public class FollowSoneAjaxPage extends JsonPage { + + /** + * Creates a new “follow Sone” AJAX page. + * + * @param webInterface + * The Sone web interface + */ + public FollowSoneAjaxPage(WebInterface webInterface) { + super("ajax/followSone.ajax", webInterface); + } + + /** + * {@inheritDoc} + */ + @Override + protected JsonObject createJsonObject(Request request) { + String soneId = request.getHttpRequest().getParam("sone"); + Sone sone = webInterface.core().getSone(soneId); + if (sone == null) { + return new JsonObject().put("success", false).put("error", "invalid-sone-id"); + } + Sone currentSone = getCurrentSone(request.getToadletContext()); + if (currentSone == null) { + return new JsonObject().put("success", false).put("error", "auth-required"); + } + currentSone.addFriend(sone); + return new JsonObject().put("success", true); + } + +}