From 829f629756e5402bcd3e9f6ef1f9c6dbffbabb11 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Wed, 17 Apr 2024 14:46:29 +0800
Subject: [PATCH] 55测试环境

---
 src/main/java/com/xcong/excoin/common/system/controller/LoginController.java |   72 ++++++++++++++++++++++++++++++-----
 1 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/common/system/controller/LoginController.java b/src/main/java/com/xcong/excoin/common/system/controller/LoginController.java
index c90ce97..6576bf6 100644
--- a/src/main/java/com/xcong/excoin/common/system/controller/LoginController.java
+++ b/src/main/java/com/xcong/excoin/common/system/controller/LoginController.java
@@ -1,24 +1,39 @@
 package com.xcong.excoin.common.system.controller;
 
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.crypto.SecureUtil;
 import cn.hutool.crypto.asymmetric.KeyType;
 import cn.hutool.crypto.asymmetric.RSA;
 import cn.hutool.crypto.asymmetric.Sign;
 import cn.hutool.crypto.asymmetric.SignAlgorithm;
 import com.alibaba.fastjson.JSONObject;
+import com.xcong.excoin.common.LoginUserUtils;
+import com.xcong.excoin.common.annotations.SubmitRepeat;
 import com.xcong.excoin.common.contants.AppContants;
+import com.xcong.excoin.common.enumerates.CoinTypeEnum;
 import com.xcong.excoin.common.response.Result;
 import com.xcong.excoin.common.system.bean.LoginUserBean;
 import com.xcong.excoin.common.system.dto.LoginDto;
 import com.xcong.excoin.common.system.dto.RegisterDto;
+import com.xcong.excoin.common.system.vo.MemberInfoVo;
 import com.xcong.excoin.configurations.properties.ApplicationProperties;
 import com.xcong.excoin.configurations.properties.SecurityProperties;
+import com.xcong.excoin.modules.coin.service.CoinService;
+import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
+import com.xcong.excoin.modules.member.dao.MemberWalletContractDao;
+import com.xcong.excoin.modules.member.entity.MemberEntity;
+import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
+import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
 import com.xcong.excoin.modules.member.service.MemberService;
+import com.xcong.excoin.utils.CoinTypeConvert;
 import com.xcong.excoin.utils.RedisUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
@@ -27,7 +42,10 @@
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -54,18 +72,17 @@
     @Resource
     private AuthenticationManagerBuilder authenticationManagerBuilder;
 
+    @Autowired
+    private CoinService coinService;
+
     @Resource
     private RedisUtils redisUtils;
 
     @ApiOperation(value = "登陆接口", notes = "登陆接口")
     @PostMapping("/login")
-    public Result login(@RequestBody @Validated LoginDto loginDto) {
-        // 使用md5加密前端传来的密码
-        Sign sign = SecureUtil.sign(SignAlgorithm.MD5withRSA);
-        byte[] pwdByte = sign.sign(loginDto.getPassword().getBytes());
-
+    public Result login(@RequestBody @Validated LoginDto loginDto, HttpServletRequest request) {
         // 将账号密码交给spring security验证,并调用userServiceDetails
-        UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(loginDto.getUsername(), loginDto.getPassword());
+        UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(loginDto.getUsername(), SecureUtil.md5(loginDto.getPassword()));
         Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authToken);
 
         // 获取当前验证过后的用户
@@ -73,25 +90,58 @@
 
         // 生成UUID作为token
         String token = IdUtil.simpleUUID();
-        redisUtils.set(AppContants.APP_LOGIN_PREFIX + token, JSONObject.toJSONString(loginUserBean), applicationProperties.getRedisExpire());
+        String redisToken = "";
+        String redisMember = "";
+        if (LoginUserUtils.isBrowser(request)) {
+            redisToken = AppContants.PC_LOGIN_PREFIX + token;
+            redisMember = AppContants.PC_LOGIN_PREFIX + loginUserBean.getMemberEntity().getId();
+        } else {
+            redisToken = AppContants.APP_LOGIN_PREFIX + token;
+            redisMember = AppContants.APP_LOGIN_PREFIX + loginUserBean.getMemberEntity().getId();
+        }
+
+        if (StrUtil.isNotBlank(redisUtils.getString(redisMember))) {
+            if (redisMember.contains(AppContants.APP_LOGIN_PREFIX)) {
+                redisUtils.del(AppContants.APP_LOGIN_PREFIX + redisUtils.getString(redisMember));
+            } else {
+                redisUtils.del(AppContants.PC_LOGIN_PREFIX + redisUtils.getString(redisMember));
+            }
+        }
+        redisUtils.set(redisToken, JSONObject.toJSONString(loginUserBean.getMemberEntity()), applicationProperties.getRedisExpire());
+        redisUtils.set(redisMember, token);
         Map<String, Object> authInfo = new HashMap<>();
+        //获取返回的个人信息
+        MemberInfoVo memberInfoVo = new MemberInfoVo();
+        MemberEntity memberEntity = loginUserBean.getMemberEntity();
+        memberInfoVo.setEmail(memberEntity.getEmail());
+        memberInfoVo.setPhone(memberEntity.getPhone());
+        memberInfoVo.setInviteId(memberEntity.getInviteId());
+        memberInfoVo.setFingerprintState(memberEntity.getFingerprintState());
         // 开启debug模式,则将加密后的token返回
         if (applicationProperties.isDebug()) {
             authInfo.put("token", token);
-            authInfo.put("rsaToken", generateAsaToken(token));
-            authInfo.put("user", loginUserBean);
+            authInfo.put("rsaToken", AppContants.TOKEN_START_WITH + generateAsaToken(token));
+            authInfo.put("user", memberInfoVo);
         } else {
             authInfo.put("token", token);
-            authInfo.put("user", loginUserBean);
+            authInfo.put("user", memberInfoVo);
+        }
+
+        BigDecimal total = BigDecimal.ZERO;
+        if (total.compareTo(AppContants.BASE_MIN_AMOUNT) > 0) {
+            authInfo.put("baseUrl", AppContants.BASE_URL_L2);
+        } else {
+            authInfo.put("baseUrl", AppContants.BASE_URL_L1);
         }
         return Result.ok("success", authInfo);
     }
 
     public String generateAsaToken(String token) {
         RSA rsa = new RSA(null, securityProperties.getPublicKey());
-        return rsa.encryptBase64(token + "_" +System.currentTimeMillis(), KeyType.PublicKey);
+        return rsa.encryptBase64(token + "_" + System.currentTimeMillis(), KeyType.PublicKey);
     }
 
+    @SubmitRepeat
     @ApiOperation(value = "app注册接口", notes = "app注册接口,验证码必须输入可默认为123456")
     @PostMapping(value = "/register")
     public Result register(@RequestBody @Validated RegisterDto registerDto) {

--
Gitblit v1.9.1