X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FLikePage.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FLikePage.java;h=e9d79bac76e4b20a6ea9890cf87711abcbe0ac8f;hb=9022be629f86cd0d85477c65dbd6a8085c48a4d7;hp=0000000000000000000000000000000000000000;hpb=c80d8668e387886c7fbda86e4196f65ba2e3a49c;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/web/LikePage.java b/src/main/java/net/pterodactylus/sone/web/LikePage.java
new file mode 100644
index 0000000..e9d79ba
--- /dev/null
+++ b/src/main/java/net/pterodactylus/sone/web/LikePage.java
@@ -0,0 +1,80 @@
+/*
+ * Sone - LikePage.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;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.page.Page.Request.Method;
+import net.pterodactylus.util.template.Template;
+
+/**
+ * Page that lets the user like a {@link Post}.
+ *
+ * @author David âBombeâ Roden
+ */
+public class LikePage extends SoneTemplatePage {
+
+ /**
+ * Creates a new âlike postâ page.
+ *
+ * @param template
+ * The template to render
+ * @param webInterface
+ * The Sone web interface
+ */
+ public LikePage(Template template, WebInterface webInterface) {
+ super("like.html", template, "Page.LikePost.Title", webInterface);
+ }
+
+ //
+ // TEMPLATEPAGE METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void processTemplate(Request request, Template template) throws RedirectException {
+ super.processTemplate(request, template);
+ if (request.getMethod() == Method.POST) {
+ String type=request.getHttpRequest().getPartAsStringFailsafe("type", 16);
+ String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36);
+ String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64);
+ Sone currentSone = getCurrentSone(request.getToadletContext());
+ if ("post".equals(type)) {
+ currentSone.addLikedPostId(id);
+ } else if ("reply".equals(type)) {
+ currentSone.addLikedReplyId(id);
+ }
+ throw new RedirectException(returnPage);
+ }
+ }
+
+ //
+ // SONETEMPLATEPAGE METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean requiresLogin() {
+ return true;
+ }
+
+}