Skip to content

Commit

Permalink
使用apiKey登录Web
Browse files Browse the repository at this point in the history
  • Loading branch information
adlered committed Oct 29, 2024
1 parent f9e7f0f commit 06b5006
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/main/java/org/b3log/symphony/processor/ApiProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.http.Dispatcher;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.Response;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
Expand All @@ -37,16 +39,14 @@
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.service.ServiceException;
import org.b3log.latke.util.Crypts;
import org.b3log.symphony.model.Follow;
import org.b3log.symphony.model.Role;
import org.b3log.symphony.model.SystemSettings;
import org.b3log.symphony.model.UserExt;
import org.b3log.symphony.model.*;
import org.b3log.symphony.processor.bot.ChatRoomBot;
import org.b3log.symphony.processor.middleware.CSRFMidware;
import org.b3log.symphony.processor.middleware.LoginCheckMidware;
import org.b3log.symphony.repository.UploadRepository;
import org.b3log.symphony.repository.UserRepository;
import org.b3log.symphony.service.*;
import org.b3log.symphony.util.Sessions;
import org.b3log.symphony.util.StatusCodes;
import org.b3log.symphony.util.Symphonys;
import org.json.JSONObject;
Expand Down Expand Up @@ -128,6 +128,25 @@ public static void register() {
final RewardQueryService rewardQueryService = beanManager.getReference(RewardQueryService.class);
Dispatcher.get("/api/article/reward/senders/{aId}", rewardQueryService::rewardedSenders);
Dispatcher.post(Symphonys.get("callback.url"), apiProcessor::callbackFromQiNiu);
Dispatcher.get("/loginWebInApiKey", apiProcessor::loginWebInApiKey);
}

public void loginWebInApiKey(final RequestContext context) {
JSONObject currentUser;
try {
currentUser = ApiProcessor.getUserByKey(context.param("apiKey"));
} catch (NullPointerException ignored) {
context.renderJSON(StatusCodes.ERR).renderMsg("ApiKey 错误。");
return;
}

if (null != currentUser) {
final Response response = context.getResponse();
response.sendRedirect(Latkes.getServePath());
Sessions.login(response, currentUser.optString(Keys.OBJECT_ID), true);
} else {
context.renderJSON(StatusCodes.ERR).renderMsg("ApiKey 错误。");
}
}

public void callbackFromQiNiu(final RequestContext context) {
Expand Down

0 comments on commit 06b5006

Please sign in to comment.