Commit 80b95c4f authored by Liang Ding's avatar Liang Ding

B3 Key 统一

parent 77d37b49
......@@ -33,6 +33,7 @@ import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Common;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Solos;
......@@ -121,7 +122,7 @@ public class B3ArticleSender extends AbstractEventListener<JSONObject> {
requestJSONObject.put(Common.BLOG, "Solo");
requestJSONObject.put(Option.ID_C_BLOG_TITLE, preference.getString(Option.ID_C_BLOG_TITLE));
requestJSONObject.put("blogHost", Latkes.getServePath());
requestJSONObject.put("userB3Key", preference.optString(Option.ID_C_KEY_OF_SOLO));
requestJSONObject.put(UserExt.USER_T_B3_KEY, preference.optString(Option.ID_C_KEY_OF_SOLO));
requestJSONObject.put("clientAdminEmail", preference.optString(Option.ID_C_ADMIN_EMAIL));
requestJSONObject.put("clientRuntimeEnv", "LOCAL");
......
......@@ -33,6 +33,7 @@ import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Common;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Solos;
......@@ -119,7 +120,7 @@ public class B3ArticleUpdater extends AbstractEventListener<JSONObject> {
requestJSONObject.put(Common.BLOG, "Solo");
requestJSONObject.put(Option.ID_C_BLOG_TITLE, preference.getString(Option.ID_C_BLOG_TITLE));
requestJSONObject.put("blogHost", Latkes.getServePath());
requestJSONObject.put("userB3Key", preference.optString(Option.ID_C_KEY_OF_SOLO));
requestJSONObject.put(UserExt.USER_T_B3_KEY, preference.optString(Option.ID_C_KEY_OF_SOLO));
requestJSONObject.put("clientAdminEmail", preference.optString(Option.ID_C_ADMIN_EMAIL));
requestJSONObject.put("clientRuntimeEnv", "LOCAL");
......
......@@ -30,6 +30,7 @@ import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Solos;
import org.json.JSONObject;
......@@ -94,7 +95,7 @@ public class B3CommentSender extends AbstractEventListener<JSONObject> {
requestJSONObject.put("clientName", "Solo");
requestJSONObject.put("clientHost", Latkes.getServePath());
requestJSONObject.put("clientAdminEmail", preference.optString(Option.ID_C_ADMIN_EMAIL));
requestJSONObject.put("userB3Key", preference.optString(Option.ID_C_KEY_OF_SOLO));
requestJSONObject.put(UserExt.USER_T_B3_KEY, preference.optString(Option.ID_C_KEY_OF_SOLO));
HttpRequest.post(ADD_COMMENT_URL).bodyText(requestJSONObject.toString()).
header("User-Agent", Solos.USER_AGENT).contentTypeJson().sendAsync();
......
......@@ -23,7 +23,7 @@ import org.apache.commons.lang.StringUtils;
* This class defines ext of user model relevant keys.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.2.0.1, Jan 28, 2019
* @version 1.2.0.2, Feb 4, 2019
* @see org.b3log.latke.model.User
* @since 0.4.1
*/
......@@ -44,11 +44,11 @@ public final class UserExt {
*/
public static final int MIN_USER_NAME_LENGTH = 1;
//// Transient
/**
* Private constructor.
* Key of user B3 key.
*/
private UserExt() {
}
public static final String USER_T_B3_KEY = "userB3Key";
/**
* Checks whether the specified name is invalid.
......@@ -83,4 +83,10 @@ public final class UserExt {
return StringUtils.containsIgnoreCase(name, "admin");
}
/**
* Private constructor.
*/
private UserExt() {
}
}
......@@ -30,6 +30,7 @@ import org.b3log.latke.servlet.renderer.JsonRenderer;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Common;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.service.ArticleMgmtService;
import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PreferenceQueryService;
......@@ -114,7 +115,7 @@ public class B3ArticleReceiver {
try {
final JSONObject article = requestJSONObject.optJSONObject(Article.ARTICLE);
final String userB3Key = article.optString("userB3Key");
final String userB3Key = article.optString(UserExt.USER_T_B3_KEY);
final JSONObject preference = preferenceQueryService.getPreference();
if (!userB3Key.equals(preference.optString(Option.ID_C_KEY_OF_SOLO))) {
......@@ -122,7 +123,7 @@ public class B3ArticleReceiver {
return;
}
article.remove("userB3Key");
article.remove(UserExt.USER_T_B3_KEY);
final JSONObject admin = userQueryService.getAdmin();
......@@ -192,7 +193,7 @@ public class B3ArticleReceiver {
try {
final JSONObject article = requestJSONObject.optJSONObject(Article.ARTICLE);
final String userB3Key = article.optString("userB3Key");
final String userB3Key = article.optString(UserExt.USER_T_B3_KEY);
final JSONObject preference = preferenceQueryService.getPreference();
if (!userB3Key.equals(preference.optString(Option.ID_C_KEY_OF_SOLO))) {
......@@ -200,7 +201,7 @@ public class B3ArticleReceiver {
return;
}
article.remove("userB3Key");
article.remove(UserExt.USER_T_B3_KEY);
final String articleId = article.getString(Keys.OBJECT_ID);
......
......@@ -35,6 +35,7 @@ import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.repository.ArticleRepository;
import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.service.ArticleMgmtService;
......@@ -150,7 +151,7 @@ public class B3CommentReceiver {
final JSONObject symphonyCmt = requestJSONObject.optJSONObject(Comment.COMMENT);
final JSONObject preference = preferenceQueryService.getPreference();
final String keyOfSolo = preference.optString(Option.ID_C_KEY_OF_SOLO);
final String key = symphonyCmt.optString("userB3Key");
final String key = symphonyCmt.optString(UserExt.USER_T_B3_KEY);
if (StringUtils.isBlank(keyOfSolo) || !keyOfSolo.equals(key)) {
ret.put(Keys.STATUS_CODE, HttpServletResponse.SC_FORBIDDEN);
......
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