Commit aa345013 authored by Liang Ding's avatar Liang Ding

Fix #12401

parent 6e37d9ab
...@@ -27,7 +27,6 @@ import org.b3log.latke.servlet.HTTPRequestMethod; ...@@ -27,7 +27,6 @@ import org.b3log.latke.servlet.HTTPRequestMethod;
import org.b3log.latke.servlet.annotation.RequestProcessing; import org.b3log.latke.servlet.annotation.RequestProcessing;
import org.b3log.latke.servlet.annotation.RequestProcessor; import org.b3log.latke.servlet.annotation.RequestProcessor;
import org.b3log.latke.servlet.renderer.JSONRenderer; import org.b3log.latke.servlet.renderer.JSONRenderer;
import org.b3log.latke.util.Requests;
import org.b3log.latke.util.freemarker.Templates; import org.b3log.latke.util.freemarker.Templates;
import org.b3log.solo.model.*; import org.b3log.solo.model.*;
import org.b3log.solo.service.CommentMgmtService; import org.b3log.solo.service.CommentMgmtService;
...@@ -38,10 +37,8 @@ import org.b3log.solo.util.Emotions; ...@@ -38,10 +37,8 @@ import org.b3log.solo.util.Emotions;
import org.b3log.solo.util.Skins; import org.b3log.solo.util.Skins;
import org.json.JSONObject; import org.json.JSONObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -51,7 +48,7 @@ import java.util.Map; ...@@ -51,7 +48,7 @@ import java.util.Map;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author ArmstrongCN * @author ArmstrongCN
* @version 1.3.3.0, Aug 31, 2017 * @version 1.3.3.1, Mar 3, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -108,7 +105,8 @@ public class CommentProcessor { ...@@ -108,7 +105,8 @@ public class CommentProcessor {
* </pre> * </pre>
* </p> * </p>
* *
* @param context the specified context, including a request json object, for example, * @param context the specified context
* @param requestJSONObject the specified request json object, for example,
* "captcha": "", * "captcha": "",
* "oId": pageId, * "oId": pageId,
* "commentName": "", * "commentName": "",
...@@ -116,15 +114,12 @@ public class CommentProcessor { ...@@ -116,15 +114,12 @@ public class CommentProcessor {
* "commentURL": "", * "commentURL": "",
* "commentContent": "", // HTML * "commentContent": "", // HTML
* "commentOriginalCommentId": "" // optional, if exists this key, the comment is an reply * "commentOriginalCommentId": "" // optional, if exists this key, the comment is an reply
* @throws ServletException servlet exception
* @throws IOException io exception
*/ */
@RequestProcessing(value = "/add-page-comment.do", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/add-page-comment.do", method = HTTPRequestMethod.POST)
public void addPageComment(final HTTPRequestContext context) throws ServletException, IOException { public void addPageComment(final HTTPRequestContext context, final JSONObject requestJSONObject) {
final HttpServletRequest httpServletRequest = context.getRequest(); final HttpServletRequest httpServletRequest = context.getRequest();
final HttpServletResponse httpServletResponse = context.getResponse(); final HttpServletResponse httpServletResponse = context.getResponse();
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(httpServletRequest, httpServletResponse);
requestJSONObject.put(Common.TYPE, Page.PAGE); requestJSONObject.put(Common.TYPE, Page.PAGE);
fillCommenter(requestJSONObject, httpServletRequest, httpServletResponse); fillCommenter(requestJSONObject, httpServletRequest, httpServletResponse);
...@@ -206,7 +201,8 @@ public class CommentProcessor { ...@@ -206,7 +201,8 @@ public class CommentProcessor {
* </pre> * </pre>
* </p> * </p>
* *
* @param context the specified context, including a request json object, for example, * @param context the specified context, including a request json object
* @param requestJSONObject the specified request json object, for example,
* "captcha": "", * "captcha": "",
* "oId": articleId, * "oId": articleId,
* "commentName": "", * "commentName": "",
...@@ -214,15 +210,12 @@ public class CommentProcessor { ...@@ -214,15 +210,12 @@ public class CommentProcessor {
* "commentURL": "", * "commentURL": "",
* "commentContent": "", * "commentContent": "",
* "commentOriginalCommentId": "" // optional, if exists this key, the comment is an reply * "commentOriginalCommentId": "" // optional, if exists this key, the comment is an reply
* @throws ServletException servlet exception
* @throws IOException io exception
*/ */
@RequestProcessing(value = "/add-article-comment.do", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/add-article-comment.do", method = HTTPRequestMethod.POST)
public void addArticleComment(final HTTPRequestContext context) throws ServletException, IOException { public void addArticleComment(final HTTPRequestContext context, final JSONObject requestJSONObject) {
final HttpServletRequest httpServletRequest = context.getRequest(); final HttpServletRequest httpServletRequest = context.getRequest();
final HttpServletResponse httpServletResponse = context.getResponse(); final HttpServletResponse httpServletResponse = context.getResponse();
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(httpServletRequest, httpServletResponse);
requestJSONObject.put(Common.TYPE, Article.ARTICLE); requestJSONObject.put(Common.TYPE, Article.ARTICLE);
fillCommenter(requestJSONObject, httpServletRequest, httpServletResponse); fillCommenter(requestJSONObject, httpServletRequest, httpServletResponse);
......
...@@ -30,7 +30,6 @@ import org.b3log.latke.servlet.annotation.RequestProcessor; ...@@ -30,7 +30,6 @@ import org.b3log.latke.servlet.annotation.RequestProcessor;
import org.b3log.latke.servlet.renderer.JSONRenderer; import org.b3log.latke.servlet.renderer.JSONRenderer;
import org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer; import org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer;
import org.b3log.latke.util.Locales; import org.b3log.latke.util.Locales;
import org.b3log.latke.util.Requests;
import org.b3log.latke.util.Sessions; import org.b3log.latke.util.Sessions;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
...@@ -53,7 +52,7 @@ import java.util.Map; ...@@ -53,7 +52,7 @@ import java.util.Map;
* Solo initialization service. * Solo initialization service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.2.0.11, May 25, 2017 * @version 1.2.0.12, Mar 3, 2018
* @since 0.4.0 * @since 0.4.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -122,19 +121,19 @@ public class InitProcessor { ...@@ -122,19 +121,19 @@ public class InitProcessor {
* Initializes Solo. * Initializes Solo.
* *
* @param context the specified http request context * @param context the specified http request context
* @param request the specified http servlet request, for example, <pre> * @param request the specified http servlet request
* @param response the specified http servlet response
* @param requestJSONObject the specified request json object, for example,
* { * {
* "userName": "", * "userName": "",
* "userEmail": "", * "userEmail": "",
* "userPassword": "" * "userPassword": ""
* } * }
* </pre>
* @param response the specified http servlet response
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = "/init", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/init", method = HTTPRequestMethod.POST)
public void initSolo(final HTTPRequestContext context, final HttpServletRequest request, public void initSolo(final HTTPRequestContext context, final HttpServletRequest request,
final HttpServletResponse response) throws Exception { final HttpServletResponse response, final JSONObject requestJSONObject) throws Exception {
if (initService.isInited()) { if (initService.isInited()) {
response.sendRedirect("/"); response.sendRedirect("/");
...@@ -143,13 +142,10 @@ public class InitProcessor { ...@@ -143,13 +142,10 @@ public class InitProcessor {
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject ret = QueryResults.defaultResult(); final JSONObject ret = QueryResults.defaultResult();
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
try { try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final String userName = requestJSONObject.optString(User.USER_NAME); final String userName = requestJSONObject.optString(User.USER_NAME);
final String userEmail = requestJSONObject.optString(User.USER_EMAIL); final String userEmail = requestJSONObject.optString(User.USER_EMAIL);
final String userPassword = requestJSONObject.optString(User.USER_PASSWORD); final String userPassword = requestJSONObject.optString(User.USER_PASSWORD);
......
...@@ -37,7 +37,6 @@ import org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer; ...@@ -37,7 +37,6 @@ import org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer;
import org.b3log.latke.user.UserService; import org.b3log.latke.user.UserService;
import org.b3log.latke.user.UserServiceFactory; import org.b3log.latke.user.UserServiceFactory;
import org.b3log.latke.util.MD5; import org.b3log.latke.util.MD5;
import org.b3log.latke.util.Requests;
import org.b3log.latke.util.Sessions; import org.b3log.latke.util.Sessions;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
...@@ -65,7 +64,7 @@ import java.util.Map; ...@@ -65,7 +64,7 @@ import java.util.Map;
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a> * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @author <a href="mailto:dongxu.wang@acm.org">Dongxu Wang</a> * @author <a href="mailto:dongxu.wang@acm.org">Dongxu Wang</a>
* @author <a href="https://github.com/nanolikeyou">nanolikeyou</a> * @author <a href="https://github.com/nanolikeyou">nanolikeyou</a>
* @version 1.1.1.10, Sep 21, 2017 * @version 1.1.1.11, Mar 3, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -177,9 +176,10 @@ public class LoginProcessor { ...@@ -177,9 +176,10 @@ public class LoginProcessor {
* </p> * </p>
* *
* @param context the specified context * @param context the specified context
* @param requestJSONObject the specified request json object
*/ */
@RequestProcessing(value = "/login", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/login", method = HTTPRequestMethod.POST)
public void login(final HTTPRequestContext context) { public void login(final HTTPRequestContext context, final JSONObject requestJSONObject) {
final HttpServletRequest request = context.getRequest(); final HttpServletRequest request = context.getRequest();
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
...@@ -193,7 +193,6 @@ public class LoginProcessor { ...@@ -193,7 +193,6 @@ public class LoginProcessor {
jsonObject.put(Keys.MSG, loginFailLabel); jsonObject.put(Keys.MSG, loginFailLabel);
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
final String userEmail = requestJSONObject.getString(User.USER_EMAIL); final String userEmail = requestJSONObject.getString(User.USER_EMAIL);
final String userPwd = requestJSONObject.getString(User.USER_PASSWORD); final String userPwd = requestJSONObject.getString(User.USER_PASSWORD);
...@@ -286,11 +285,10 @@ public class LoginProcessor { ...@@ -286,11 +285,10 @@ public class LoginProcessor {
* </p> * </p>
* *
* @param context the specified context * @param context the specified context
* @param requestJSONObject the specified request json object
*/ */
@RequestProcessing(value = "/forgot", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/forgot", method = HTTPRequestMethod.POST)
public void forgot(final HTTPRequestContext context) { public void forgot(final HTTPRequestContext context, final JSONObject requestJSONObject) {
final HttpServletRequest request = context.getRequest();
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject(); final JSONObject jsonObject = new JSONObject();
...@@ -300,7 +298,6 @@ public class LoginProcessor { ...@@ -300,7 +298,6 @@ public class LoginProcessor {
jsonObject.put("succeed", false); jsonObject.put("succeed", false);
jsonObject.put(Keys.MSG, langPropsService.get("resetPwdSuccessMsg")); jsonObject.put(Keys.MSG, langPropsService.get("resetPwdSuccessMsg"));
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
final String userEmail = requestJSONObject.getString(User.USER_EMAIL); final String userEmail = requestJSONObject.getString(User.USER_EMAIL);
if (Strings.isEmptyOrNull(userEmail)) { if (Strings.isEmptyOrNull(userEmail)) {
...@@ -337,10 +334,10 @@ public class LoginProcessor { ...@@ -337,10 +334,10 @@ public class LoginProcessor {
* </p> * </p>
* *
* @param context the specified context * @param context the specified context
* @param requestJSONObject the specified request json object
*/ */
@RequestProcessing(value = "/reset", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/reset", method = HTTPRequestMethod.POST)
public void reset(final HTTPRequestContext context) { public void reset(final HTTPRequestContext context, final JSONObject requestJSONObject) {
final HttpServletRequest request = context.getRequest();
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
...@@ -349,9 +346,6 @@ public class LoginProcessor { ...@@ -349,9 +346,6 @@ public class LoginProcessor {
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
try { try {
final JSONObject requestJSONObject;
requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
final String token = requestJSONObject.getString("token"); final String token = requestJSONObject.getString("token");
final String newPwd = requestJSONObject.getString("newPwd"); final String newPwd = requestJSONObject.getString("newPwd");
final JSONObject passwordResetOption = optionQueryService.getOptionById(token); final JSONObject passwordResetOption = optionQueryService.getOptionById(token);
......
...@@ -51,7 +51,7 @@ import java.util.stream.Collectors; ...@@ -51,7 +51,7 @@ import java.util.stream.Collectors;
* Article console request processing. * Article console request processing.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.0, Feb 15, 2018 * @version 1.1.0.1, Mar 3, 2018
* @since 0.4.0 * @since 0.4.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -554,7 +554,9 @@ public class ArticleConsole { ...@@ -554,7 +554,9 @@ public class ArticleConsole {
* </p> * </p>
* *
* @param context the specified http request context * @param context the specified http request context
* @param request the specified http servlet request, for example, * @param request the specified http servlet request
* @param response the specified http servlet response
* @param requestJSONObject the specified request json object, for example,
* { * {
* "article": { * "article": {
* "oId": "", * "oId": "",
...@@ -570,12 +572,11 @@ public class ArticleConsole { ...@@ -570,12 +572,11 @@ public class ArticleConsole {
* "postToCommunity": boolean * "postToCommunity": boolean
* } * }
* } * }
* @param response the specified http servlet response
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = "/console/article/", method = HTTPRequestMethod.PUT) @RequestProcessing(value = "/console/article/", method = HTTPRequestMethod.PUT)
public void updateArticle(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) public void updateArticle(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response,
throws Exception { final JSONObject requestJSONObject) throws Exception {
if (!userQueryService.isLoggedIn(request, response)) { if (!userQueryService.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
return; return;
...@@ -586,7 +587,6 @@ public class ArticleConsole { ...@@ -586,7 +587,6 @@ public class ArticleConsole {
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
try { try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final JSONObject article = requestJSONObject.getJSONObject(Article.ARTICLE); final JSONObject article = requestJSONObject.getJSONObject(Article.ARTICLE);
final String articleId = article.getString(Keys.OBJECT_ID); final String articleId = article.getString(Keys.OBJECT_ID);
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
...@@ -624,7 +624,10 @@ public class ArticleConsole { ...@@ -624,7 +624,10 @@ public class ArticleConsole {
* </pre> * </pre>
* </p> * </p>
* *
* @param request the specified http servlet request, for example, * @param request the specified http servlet request
* @param response the specified http servlet response
* @param context the specified http request context
* @param requestJSONObject the specified request json object, for example,
* { * {
* "article": { * "article": {
* "articleTitle": "", * "articleTitle": "",
...@@ -639,13 +642,11 @@ public class ArticleConsole { ...@@ -639,13 +642,11 @@ public class ArticleConsole {
* "articleViewPwd": "" * "articleViewPwd": ""
* } * }
* } * }
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = "/console/article/", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/console/article/", method = HTTPRequestMethod.POST)
public void addArticle(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void addArticle(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context,
throws Exception { final JSONObject requestJSONObject) throws Exception {
if (!userQueryService.isLoggedIn(request, response)) { if (!userQueryService.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
return; return;
...@@ -656,7 +657,6 @@ public class ArticleConsole { ...@@ -656,7 +657,6 @@ public class ArticleConsole {
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
try { try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final JSONObject currentUser = userQueryService.getCurrentUser(request); final JSONObject currentUser = userQueryService.getCurrentUser(request);
requestJSONObject.getJSONObject(Article.ARTICLE).put(Article.ARTICLE_AUTHOR_EMAIL, currentUser.getString(User.USER_EMAIL)); requestJSONObject.getJSONObject(Article.ARTICLE).put(Article.ARTICLE_AUTHOR_EMAIL, currentUser.getString(User.USER_EMAIL));
......
...@@ -50,7 +50,7 @@ import java.util.Set; ...@@ -50,7 +50,7 @@ import java.util.Set;
* Category console request processing. * Category console request processing.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.1.1, Apr 22, 2017 * @version 1.1.1.2, Mar 3, 2018
* @since 2.0.0 * @since 2.0.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -103,16 +103,17 @@ public class CategoryConsole { ...@@ -103,16 +103,17 @@ public class CategoryConsole {
* </pre> * </pre>
* </p> * </p>
* *
* @param request the specified http servlet request, for example, * @param request the specified http servlet request
* "oId": "",
* "direction": "" // "up"/"down"
* @param response the specified http servlet response * @param response the specified http servlet response
* @param context the specified http request context * @param context the specified http request context
* @param requestJSONObject the specified request json object, for example,
* "oId": "",
* "direction": "" // "up"/"down"
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = "/console/category/order/", method = HTTPRequestMethod.PUT) @RequestProcessing(value = "/console/category/order/", method = HTTPRequestMethod.PUT)
public void changeOrder(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void changeOrder(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context,
throws Exception { final JSONObject requestJSONObject) throws Exception {
if (!userQueryService.isAdminLoggedIn(request)) { if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
...@@ -124,7 +125,6 @@ public class CategoryConsole { ...@@ -124,7 +125,6 @@ public class CategoryConsole {
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
try { try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final String categoryId = requestJSONObject.getString(Keys.OBJECT_ID); final String categoryId = requestJSONObject.getString(Keys.OBJECT_ID);
final String direction = requestJSONObject.getString(Common.DIRECTION); final String direction = requestJSONObject.getString(Common.DIRECTION);
...@@ -263,19 +263,20 @@ public class CategoryConsole { ...@@ -263,19 +263,20 @@ public class CategoryConsole {
* </pre> * </pre>
* </p> * </p>
* *
* @param request the specified http servlet request, * @param request the specified http servlet request
* @param context the specified http request context
* @param response the specified http servlet response
* @param requestJSONObject the specified request json object, for example,
* "oId": "", * "oId": "",
* "categoryTitle": "", * "categoryTitle": "",
* "categoryURI": "", // optional * "categoryURI": "", // optional
* "categoryDescription": "", // optional * "categoryDescription": "", // optional
* "categoryTags": "tag1, tag2" // optional * "categoryTags": "tag1, tag2" // optional
* @param context the specified http request context
* @param response the specified http servlet response
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = "/console/category/", method = HTTPRequestMethod.PUT) @RequestProcessing(value = "/console/category/", method = HTTPRequestMethod.PUT)
public void updateCategory(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void updateCategory(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context,
throws Exception { final JSONObject requestJSONObject) throws Exception {
if (!userQueryService.isAdminLoggedIn(request)) { if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
...@@ -289,8 +290,6 @@ public class CategoryConsole { ...@@ -289,8 +290,6 @@ public class CategoryConsole {
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
try { try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
String tagsStr = requestJSONObject.optString(Category.CATEGORY_T_TAGS); String tagsStr = requestJSONObject.optString(Category.CATEGORY_T_TAGS);
tagsStr = tagsStr.replaceAll(",", ",").replaceAll("、", ","); tagsStr = tagsStr.replaceAll(",", ",").replaceAll("、", ",");
final String[] tagTitles = tagsStr.split(","); final String[] tagTitles = tagsStr.split(",");
...@@ -394,17 +393,19 @@ public class CategoryConsole { ...@@ -394,17 +393,19 @@ public class CategoryConsole {
* </pre> * </pre>
* </p> * </p>
* *
* @param request the specified http servlet request, * @param request the specified http servlet request
* @param response the specified http servlet response
* @param context the specified http request context
* @param requestJSONObject the specified request json object, for example,
* "categoryTitle": "", * "categoryTitle": "",
* "categoryURI": "", // optional * "categoryURI": "", // optional
* "categoryDescription": "", // optional * "categoryDescription": "", // optional
* "categoryTags": "tag1, tag2" // optional * "categoryTags": "tag1, tag2" // optional
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = "/console/category/", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/console/category/", method = HTTPRequestMethod.POST)
public void addCategory(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void addCategory(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context,
final JSONObject requestJSONObject)
throws Exception { throws Exception {
if (!userQueryService.isAdminLoggedIn(request)) { if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
...@@ -419,8 +420,6 @@ public class CategoryConsole { ...@@ -419,8 +420,6 @@ public class CategoryConsole {
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
try { try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
String tagsStr = requestJSONObject.optString(Category.CATEGORY_T_TAGS); String tagsStr = requestJSONObject.optString(Category.CATEGORY_T_TAGS);
tagsStr = tagsStr.replaceAll(",", ",").replaceAll("、", ","); tagsStr = tagsStr.replaceAll(",", ",").replaceAll("、", ",");
final String[] tagTitles = tagsStr.split(","); final String[] tagTitles = tagsStr.split(",");
......
...@@ -41,7 +41,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -41,7 +41,7 @@ import javax.servlet.http.HttpServletResponse;
* Link console request processing. * Link console request processing.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.3, Aug 9, 2012 * @version 1.0.0.4, Mar 3, 2018
* @since 0.4.0 * @since 0.4.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -190,20 +190,19 @@ public class LinkConsole { ...@@ -190,20 +190,19 @@ public class LinkConsole {
* </pre> * </pre>
* </p> * </p>
* *
* @param request the specified http servlet request, for example, * @param request the specified http servlet request
* @param response the specified http servlet response
* @param context the specified http request context
* @param requestJSONObject the specified request json object, for example,
* { * {
* "oId": "", * "oId": "",
* "direction": "" // "up"/"down" * "direction": "" // "up"/"down"
* } * }
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = "/console/link/order/", method = HTTPRequestMethod.PUT) @RequestProcessing(value = "/console/link/order/", method = HTTPRequestMethod.PUT)
public void changeOrder(final HttpServletRequest request, public void changeOrder(final HttpServletRequest request, final HttpServletResponse response,
final HttpServletResponse response, final HTTPRequestContext context, final JSONObject requestJSONObject) throws Exception {
final HTTPRequestContext context)
throws Exception {
if (!userQueryService.isAdminLoggedIn(request)) { if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
...@@ -216,7 +215,6 @@ public class LinkConsole { ...@@ -216,7 +215,6 @@ public class LinkConsole {
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
try { try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final String linkId = requestJSONObject.getString(Keys.OBJECT_ID); final String linkId = requestJSONObject.getString(Keys.OBJECT_ID);
final String direction = requestJSONObject.getString(Common.DIRECTION); final String direction = requestJSONObject.getString(Common.DIRECTION);
...@@ -249,7 +247,10 @@ public class LinkConsole { ...@@ -249,7 +247,10 @@ public class LinkConsole {
* </pre> * </pre>
* </p> * </p>
* *
* @param request the specified http servlet request, for example, * @param request the specified http servlet request
* @param response the specified http servlet response
* @param context the specified http request context
* @param requestJSONObject the specified request json object, for example,
* { * {
* "link": { * "link": {
* "linkTitle": "", * "linkTitle": "",
...@@ -257,13 +258,11 @@ public class LinkConsole { ...@@ -257,13 +258,11 @@ public class LinkConsole {
* "linkDescription": "" * "linkDescription": ""
* } * }
* } * }
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = "/console/link/", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/console/link/", method = HTTPRequestMethod.POST)
public void addLink(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void addLink(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context,
throws Exception { final JSONObject requestJSONObject) throws Exception {
if (!userQueryService.isAdminLoggedIn(request)) { if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
return; return;
...@@ -275,8 +274,6 @@ public class LinkConsole { ...@@ -275,8 +274,6 @@ public class LinkConsole {
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
try { try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final String linkId = linkMgmtService.addLink(requestJSONObject); final String linkId = linkMgmtService.addLink(requestJSONObject);
ret.put(Keys.OBJECT_ID, linkId); ret.put(Keys.OBJECT_ID, linkId);
......
...@@ -45,7 +45,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -45,7 +45,7 @@ import javax.servlet.http.HttpServletResponse;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a> * @author <a href="mailto:385321165@qq.com">DASHU</a>
* @version 1.2.0.5, Mar 31, 2017 * @version 1.2.0.6, Mar 3, 2018
* @since 0.4.0 * @since 0.4.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -92,7 +92,10 @@ public class UserConsole { ...@@ -92,7 +92,10 @@ public class UserConsole {
* </pre> * </pre>
* </p> * </p>
* *
* @param request the specified http servlet request, for example, * @param request the specified http servlet request
* @param context the specified http request context
* @param response the specified http servlet response
* @param requestJSONObject the specified request json object, for example,
* "oId": "", * "oId": "",
* "userName": "", * "userName": "",
* "userEmail": "", * "userEmail": "",
...@@ -100,27 +103,23 @@ public class UserConsole { ...@@ -100,27 +103,23 @@ public class UserConsole {
* "userRole": "", // optional * "userRole": "", // optional
* "userURL": "", // optional * "userURL": "", // optional
* "userAvatar": "" // optional * "userAvatar": "" // optional
* @param context the specified http request context
* @param response the specified http servlet response
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = "/console/user/", method = HTTPRequestMethod.PUT) @RequestProcessing(value = "/console/user/", method = HTTPRequestMethod.PUT)
public void updateUser(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void updateUser(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context,
final JSONObject requestJSONObject)
throws Exception { throws Exception {
if (!userQueryService.isAdminLoggedIn(request)) { if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
return; return;
} }
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
try { try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
userMgmtService.updateUser(requestJSONObject); userMgmtService.updateUser(requestJSONObject);
ret.put(Keys.STATUS_CODE, true); ret.put(Keys.STATUS_CODE, true);
...@@ -150,36 +149,28 @@ public class UserConsole { ...@@ -150,36 +149,28 @@ public class UserConsole {
* </pre> * </pre>
* </p> * </p>
* *
* @param request the specified http servlet request, for example, * @param context the specified http request context
* @param requestJSONObject the specified request json object, for example,
* "userName": "", * "userName": "",
* "userEmail": "", * "userEmail": "",
* "userPassword": "", * "userPassword": "",
* "userURL": "", // optional, uses 'servePath' instead if not specified * "userURL": "", // optional, uses 'servePath' instead if not specified
* "userRole": "", // optional, uses {@value org.b3log.latke.model.Role#DEFAULT_ROLE} instead if not specified * "userRole": "", // optional, uses {@value org.b3log.latke.model.Role#DEFAULT_ROLE} instead if not specified
* "userAvatar": "" // optional * "userAvatar": "" // optional
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/ */
@RequestProcessing(value = "/console/user/", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/console/user/", method = HTTPRequestMethod.POST)
public void addUser(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void addUser(final HttpServletRequest request, final HTTPRequestContext context, final JSONObject requestJSONObject) {
throws Exception {
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
try { try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
if (userQueryService.isAdminLoggedIn(request)) { // if the administrator register a new user, treats the new user as a normal user if (userQueryService.isAdminLoggedIn(request)) { // if the administrator register a new user, treats the new user as a normal user
// (defaultRole) who could post article // (defaultRole) who could post article
requestJSONObject.put(User.USER_ROLE, Role.DEFAULT_ROLE); requestJSONObject.put(User.USER_ROLE, Role.DEFAULT_ROLE);
} else { } else {
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
if (!preference.optBoolean(Option.ID_C_ALLOW_REGISTER)) { if (!preference.optBoolean(Option.ID_C_ALLOW_REGISTER)) {
ret.put(Keys.STATUS_CODE, false); ret.put(Keys.STATUS_CODE, false);
ret.put(Keys.MSG, langPropsService.get("notAllowRegisterLabel")); ret.put(Keys.MSG, langPropsService.get("notAllowRegisterLabel"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment