From a06c82e4ecfea6452f4d90aa41189f294c434160 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 5 Apr 2017 15:12:39 +0300 Subject: juick-www: Springify some controllers --- .../java/com/juick/www/controllers/XMPPPost.java | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'juick-www/src/main/java/com/juick/www/controllers/XMPPPost.java') diff --git a/juick-www/src/main/java/com/juick/www/controllers/XMPPPost.java b/juick-www/src/main/java/com/juick/www/controllers/XMPPPost.java index 888d25c4..330f277c 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/XMPPPost.java +++ b/juick-www/src/main/java/com/juick/www/controllers/XMPPPost.java @@ -1,6 +1,7 @@ package com.juick.www.controllers; import com.juick.server.util.HttpBadRequestException; +import com.juick.server.util.HttpForbiddenException; import com.juick.server.util.HttpUtils; import com.juick.service.TagService; import com.juick.util.UserUtils; @@ -17,8 +18,6 @@ import rocks.xmpp.core.stanza.model.Message; import rocks.xmpp.extensions.oob.model.x.OobX; import javax.inject.Inject; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -37,16 +36,16 @@ public class XMPPPost { TagService tagService; @PostMapping("/post2") - public void doPostMessage(HttpServletRequest request, HttpServletResponse response, - @RequestParam(required = false) String img, - @RequestParam(required = false) MultipartFile attach) throws IOException { + public String doPostMessage(@RequestParam(name = "body") String bodyParam, + @RequestParam(required = false) String img, + @RequestParam(required = false) String referer, + @RequestParam(required = false) MultipartFile attach) throws IOException { com.juick.User visitor = UserUtils.getCurrentUser(); if (visitor.getUid() == 0 || visitor.isBanned()) { - response.sendError(HttpServletResponse.SC_FORBIDDEN); - return; + throw new HttpForbiddenException(); } - String body = request.getParameter("body").replace("\r", StringUtils.EMPTY); + String body = bodyParam.replace("\r", StringUtils.EMPTY); String attachmentFName = HttpUtils.receiveMultiPartFile(attach, webApp.getTmpDir()); @@ -73,12 +72,10 @@ public class XMPPPost { } catch (URISyntaxException e1) { logger.warn("attachment error", e1); } - String referer = request.getHeader("referer"); if (StringUtils.isBlank(referer) || referer.substring(0, 21).equals("http://juick.com/post") || referer.substring(0, 22).equals("https://juick.com/post")) { - response.sendRedirect("/?show=my"); - return; + return "redirect:/?show=my"; } - response.sendRedirect(referer); + return "redirect:" + referer; } } -- cgit v1.2.3