Commit 8e75346e authored by Liang Ding's avatar Liang Ding

BAE 下服务端不校验评论验证码

parent bc416c8b
...@@ -23,6 +23,8 @@ import javax.servlet.http.HttpServletRequest; ...@@ -23,6 +23,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.RuntimeEnv;
import org.b3log.latke.annotation.RequestProcessing; import org.b3log.latke.annotation.RequestProcessing;
import org.b3log.latke.annotation.RequestProcessor; import org.b3log.latke.annotation.RequestProcessor;
import org.b3log.latke.service.LangPropsService; import org.b3log.latke.service.LangPropsService;
...@@ -41,7 +43,7 @@ import org.json.JSONObject; ...@@ -41,7 +43,7 @@ import org.json.JSONObject;
* Comment processor. * Comment processor.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.1.0.7, Aug 9, 2012 * @version 1.1.0.8, Sep 10, 2012
* @since 0.3.1 * @since 0.3.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -81,7 +83,7 @@ public final class CommentProcessor { ...@@ -81,7 +83,7 @@ public final class CommentProcessor {
* including a request json object, for example, * including a request json object, for example,
* <pre> * <pre>
* { * {
* "captcha": "", * "captcha": "", // optional if on BAE
* "oId": pageId, * "oId": pageId,
* "commentName": "", * "commentName": "",
* "commentEmail": "", * "commentEmail": "",
...@@ -113,18 +115,21 @@ public final class CommentProcessor { ...@@ -113,18 +115,21 @@ public final class CommentProcessor {
return; return;
} }
final String captcha = requestJSONObject.optString(CaptchaProcessor.CAPTCHA); if (RuntimeEnv.BAE != Latkes.getRuntimeEnv()) {
final HttpSession session = httpServletRequest.getSession(false); final String captcha = requestJSONObject.optString(CaptchaProcessor.CAPTCHA);
if (null != session) {
final String storedCaptcha = (String) session.getAttribute(CaptchaProcessor.CAPTCHA);
if (null == storedCaptcha || !storedCaptcha.equals(captcha)) {
jsonObject.put(Keys.STATUS_CODE, false);
jsonObject.put(Keys.MSG, langPropsService.get("captchaErrorLabel"));
return; final HttpSession session = httpServletRequest.getSession(false);
} if (null != session) {
final String storedCaptcha = (String) session.getAttribute(CaptchaProcessor.CAPTCHA);
if (null == storedCaptcha || !storedCaptcha.equals(captcha)) {
jsonObject.put(Keys.STATUS_CODE, false);
jsonObject.put(Keys.MSG, langPropsService.get("captchaErrorLabel"));
session.removeAttribute(CaptchaProcessor.CAPTCHA); return;
}
session.removeAttribute(CaptchaProcessor.CAPTCHA);
}
} }
try { try {
...@@ -193,20 +198,23 @@ public final class CommentProcessor { ...@@ -193,20 +198,23 @@ public final class CommentProcessor {
return; return;
} }
final String captcha = requestJSONObject.optString(CaptchaProcessor.CAPTCHA); if (RuntimeEnv.BAE != Latkes.getRuntimeEnv()) {
final HttpSession session = httpServletRequest.getSession(false); final String captcha = requestJSONObject.optString(CaptchaProcessor.CAPTCHA);
if (null != session) {
final String storedCaptcha = (String) session.getAttribute(CaptchaProcessor.CAPTCHA);
if (null == storedCaptcha || !storedCaptcha.equals(captcha)) {
jsonObject.put(Keys.STATUS_CODE, false);
jsonObject.put(Keys.MSG, langPropsService.get("captchaErrorLabel"));
return; final HttpSession session = httpServletRequest.getSession(false);
} if (null != session) {
final String storedCaptcha = (String) session.getAttribute(CaptchaProcessor.CAPTCHA);
if (null == storedCaptcha || !storedCaptcha.equals(captcha)) {
jsonObject.put(Keys.STATUS_CODE, false);
jsonObject.put(Keys.MSG, langPropsService.get("captchaErrorLabel"));
session.removeAttribute(CaptchaProcessor.CAPTCHA); return;
} }
session.removeAttribute(CaptchaProcessor.CAPTCHA);
}
}
try { try {
final JSONObject addResult = commentMgmtService.addArticleComment(requestJSONObject); final JSONObject addResult = commentMgmtService.addArticleComment(requestJSONObject);
......
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