From d98c7875c62e6551ad8aee081242aad8d5f13efe Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Mon, 27 Apr 2026 17:14:18 +0800
Subject: [PATCH] 1
---
src/main/java/com/nq/controller/AgentApiController.java | 86 +++++++++++++++++++++++++++++++++++++++++-
1 files changed, 83 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/nq/controller/AgentApiController.java b/src/main/java/com/nq/controller/AgentApiController.java
index cfbb1fe..8884352 100644
--- a/src/main/java/com/nq/controller/AgentApiController.java
+++ b/src/main/java/com/nq/controller/AgentApiController.java
@@ -2,11 +2,14 @@
import com.nq.common.ServerResponse;
-
+import com.nq.dao.AgentUserMapper;
+import com.nq.pojo.AgentUser;
+import com.nq.pojo.GoogleAuthDto;
import com.nq.pojo.UserStockSubscribe;
import com.nq.service.IAgentUserService;
import com.nq.service.IUserStockSubscribeService;
+import com.nq.service.impl.GoogleAuthenticator;
import com.nq.utils.PropertiesUtil;
import com.nq.utils.redis.CookieUtils;
@@ -25,6 +28,7 @@
import javax.servlet.http.HttpSession;
+import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,11 +55,18 @@
@Autowired
IUserStockSubscribeService iUserStockSubscribeService;
+ @Autowired
+ AgentUserMapper agentUserMapper;
+
//代理后台登录
@RequestMapping({"login.do"})
@ResponseBody
- public ServerResponse login(@RequestParam("agentPhone") String agentPhone, @RequestParam("agentPwd") String agentPwd, @RequestParam(value = "verifyCode", required = false, defaultValue = "") String verifyCode, HttpSession httpSession, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
- ServerResponse serverResponse = this.iAgentUserService.login(agentPhone, agentPwd, verifyCode, httpServletRequest);
+ public ServerResponse login(@RequestParam("agentPhone") String agentPhone,
+ @RequestParam("agentPwd") String agentPwd,
+ @RequestParam(value = "verifyCode", required = false, defaultValue = "") String verifyCode,
+ @RequestParam(value = "googleAuthCode", required = false) Integer googleAuthCode,
+ HttpSession httpSession, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
+ ServerResponse serverResponse = this.iAgentUserService.login(agentPhone, agentPwd, verifyCode, googleAuthCode, httpServletRequest);
String token = RedisConst.getAgentRedisKey(httpSession.getId());
if (serverResponse.isSuccess()) {
String redisSetExResult = RedisShardedPoolUtils.setEx(token,
@@ -105,4 +116,73 @@
return this.iUserStockSubscribeService.del(id, request);
}
+ @RequestMapping({"getLoginGoogleAuthSecret"})
+ @ResponseBody
+ public ServerResponse getLoginGoogleAuthSecret(HttpServletRequest request) {
+ GoogleAuthDto dto = iAgentUserService.getGoogleAuth(request);
+ if (dto == null) {
+ return ServerResponse.createByErrorMsg("请先登录");
+ }
+ return ServerResponse.createBySuccess(dto);
+ }
+
+ @RequestMapping({"bindGoogleAuth"})
+ @ResponseBody
+ public ServerResponse bindGoogleAuth(@RequestParam("googleAuthCode") String googleAuthCode,
+ @RequestParam("secret") String secret,
+ HttpServletRequest request) {
+ AgentUser currentAgent = iAgentUserService.getCurrentAgent(request);
+ if (currentAgent == null) {
+ return ServerResponse.createByErrorMsg("请先登录");
+ }
+ AgentUser agentUser = agentUserMapper.selectByPrimaryKey(currentAgent.getId());
+ if (agentUser == null) {
+ return ServerResponse.createByErrorMsg("当前用户未找到");
+ }
+ if (Boolean.TRUE.equals(agentUser.getGoogleAuthBind())) {
+ return ServerResponse.createByErrorMsg("谷歌验证码已绑定");
+ }
+ if (StringUtils.isBlank(secret) || StringUtils.isBlank(googleAuthCode)) {
+ return ServerResponse.createByErrorMsg("参数不能为空");
+ }
+ long t = System.currentTimeMillis();
+ GoogleAuthenticator ga = new GoogleAuthenticator();
+ ga.setWindowSize(5);
+ boolean userFlag = ga.check_code(secret, Long.valueOf(googleAuthCode), t);
+ if (!userFlag) {
+ return ServerResponse.createByErrorMsg("谷歌验证码错误");
+ }
+ agentUser.setGoogleAuthBind(true);
+ agentUser.setGoogleAuthSecret(secret);
+ agentUserMapper.updateByPrimaryKeySelective(agentUser);
+ return ServerResponse.createBySuccess();
+ }
+
+ @RequestMapping({"unbindingGoogleAuth"})
+ @ResponseBody
+ public ServerResponse unbindingGoogleAuth(@RequestParam("rootGoogleAuthCode") String rootGoogleAuthCode,
+ HttpServletRequest request) {
+ AgentUser currentAgent = iAgentUserService.getCurrentAgent(request);
+ if (currentAgent == null) {
+ return ServerResponse.createByErrorMsg("请先登录");
+ }
+ AgentUser agentUser = agentUserMapper.selectByPrimaryKey(currentAgent.getId());
+ if (agentUser == null) {
+ return ServerResponse.createByErrorMsg("当前用户未找到");
+ }
+ if (!Boolean.TRUE.equals(agentUser.getGoogleAuthBind())) {
+ return ServerResponse.createByErrorMsg("谷歌验证码未绑定,无需解绑!");
+ }
+ long t = System.currentTimeMillis();
+ GoogleAuthenticator ga = new GoogleAuthenticator();
+ ga.setWindowSize(5);
+ boolean flag = ga.check_code(agentUser.getGoogleAuthSecret(), Long.valueOf(rootGoogleAuthCode), t);
+ if (!flag) {
+ return ServerResponse.createByErrorMsg("谷歌验证码错误");
+ }
+ agentUser.setGoogleAuthBind(false);
+ agentUser.setGoogleAuthSecret("");
+ agentUserMapper.updateByPrimaryKeySelective(agentUser);
+ return ServerResponse.createBySuccess();
+ }
}
--
Gitblit v1.9.3