Commit aa345013 authored by Liang Ding's avatar Liang Ding

Fix #12401

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