Ver Fonte

更改登录日志记录地方

hym há 4 anos atrás
pai
commit
16791fe3b7

+ 7 - 6
user_auth/src/main/java/com/huaxu/controller/SmsController.java

@@ -101,19 +101,20 @@ public class SmsController {
         redisUtil.del(key.getBytes());
         return new AjaxMessage(ResultStatus.OK);
     }
-    @PostMapping("test")
+  /*  @PostMapping("test")
     @ResponseBody
     @ApiOperation(value = "发送短信")
     public void test(String phone){
         countVerify(phone);
-    }
+    }*/
     private AjaxMessage countVerify(String phone){
         LocalDate now = LocalDate.now();
         AjaxMessage ajaxMessage=new AjaxMessage(ResultStatus.OK);
-        String key = "countVerify:" + phone+now.toString();
-        byte[] countVerifyByte = redisUtil.get(key.getBytes());
-        if(countVerifyByte!=null){
-            Integer count = (Integer) ByteArrayUtils.bytesToObject(countVerifyByte).get();
+        String key = "countVerify:" + phone+":"+now.toString();
+        String countVerify = redisUtil.get(key);
+
+        if(countVerify!=null){
+            Integer count = Integer.parseInt(countVerify);
             if(count==getSendCodeMax){
                 ajaxMessage=new AjaxMessage(ResultStatus.SMS_CODE_COUNT);
             }else if(count==maxSendCodeNum){

+ 2 - 11
user_auth/src/main/java/com/huaxu/security/MyAuthenticationSuccessHandler.java

@@ -44,8 +44,7 @@ public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticat
 
     @Autowired
     private UserService userService;
-    @Autowired
-    private LoginLogMapper loginLogMapper;
+
 
 
     @SuppressWarnings("unchecked")
@@ -85,15 +84,7 @@ public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticat
         response.setContentType("application/json;charset=UTF-8");
         ObjectMapper objectMapper = new ObjectMapper();
         AjaxMessage ajaxMessage = new AjaxMessage(ResultStatus.OK,token);
-        LoginLog loginLog=new LoginLog();
-        loginLog.setName(loginUser.getName());
-        loginLog.setCreateTime(new Date());
-        loginLog.setPhone(loginUser.getPhoneNumber());
-        loginLog.setCompanyId(loginUser.getCompanyId());
-        loginLog.setDepartmentId(loginUser.getDepartmentId());
-        loginLog.setType("登录");
-        loginLog.setLoginIp(Util.getIpAddr(request));
-        loginLogMapper.insert(loginLog);
+
 
 
         response.getWriter().write(objectMapper.writeValueAsString(ajaxMessage));

+ 1 - 1
user_auth/src/main/java/com/huaxu/security/smsCode/SmsCodeCheckUserFilter.java

@@ -87,7 +87,7 @@ public class SmsCodeCheckUserFilter extends OncePerRequestFilter {
         }
 
 
-            String key = "smsCode:" +smsCode;
+            String key = "smsCode:" +mobile;
             byte[] redisValidateCodeByte = redisUtil.get(key.getBytes());
             if (redisValidateCodeByte == null) {
                 throw new SmsCodeException(ResultStatus.PHONE_VALIDATE_CODE_EXPIRED_ERROR);

+ 14 - 2
user_auth/src/main/java/com/huaxu/service/impl/UserServiceImpl.java

@@ -2,6 +2,7 @@ package com.huaxu.service.impl;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 
+import com.huaxu.dao.LoginLogMapper;
 import com.huaxu.dao.UserMapper;
 import com.huaxu.dto.UserDto;
 import com.huaxu.entity.LoginLog;
@@ -15,6 +16,7 @@ import com.huaxu.security.smsCode.SmsCodeException;
 import com.huaxu.service.UserService;
 import com.huaxu.util.ByteArrayUtils;
 import com.huaxu.util.RedisUtil;
+import com.huaxu.util.Util;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -55,6 +57,8 @@ public class UserServiceImpl implements UserService {
 
     @Autowired
     private AuthorizationServerTokenServices authorizationServerTokenServices;
+    @Autowired
+    private LoginLogMapper loginLogMapper;
 
 
     /**
@@ -206,8 +210,16 @@ public class UserServiceImpl implements UserService {
         OAuth2Authentication oAuth2AuthenticationNew = new OAuth2Authentication(oAuth2Authentication.getOAuth2Request(), authenticationTokenReslut);
 
         OAuth2AccessToken accessToken = authorizationServerTokenServices.createAccessToken(oAuth2AuthenticationNew);
-        //0404d87f-c25d-4947-b17a-0cb65210f5bb
-        //new RedisTokenStore()
+        LoginLog loginLog=new LoginLog();
+        loginLog.setName(loginUser.getName());
+        loginLog.setCreateTime(new Date());
+        loginLog.setPhone(loginUser.getPhoneNumber());
+        loginLog.setCompanyId(loginUser.getCompanyId());
+        loginLog.setDepartmentId(loginUser.getDepartmentId());
+        loginLog.setType("登录");
+        loginLog.setLoginIp(Util.getIpAddr(request));
+        loginLogMapper.insert(loginLog);
+
         return accessToken;
     }
 

+ 1 - 1
user_auth/src/main/resources/application-dev.properties

@@ -61,7 +61,7 @@ spring.kafka.consumer.properties.spring.json.trusted.packages=*
 
 #nacos
 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
-maxSendCodeNum=10
+maxSendCodeNum=50
 getSendCodeMax=5