瀏覽代碼

Signed-off-by: ljx <809268652@qq.com>把校验查询接口拆成验证码校验接口和B类查询接口

ljx 2 年之前
父節點
當前提交
20fa20db83

+ 17 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java

@@ -6,9 +6,14 @@ import java.util.concurrent.TimeUnit;
 import javax.annotation.Resource;
 import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.domain.dto.CaptchaEntity;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.FastByteArrayOutputStream;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
 import com.google.code.kaptcha.Producer;
 import com.ruoyi.common.config.RuoYiConfig;
@@ -91,4 +96,16 @@ public class CaptchaController
         ajax.put("img", Base64.encode(os.toByteArray()));
         return ajax;
     }
+
+    @PostMapping("/captchaCheck")
+    public AjaxResult validateCaptcha(@RequestBody CaptchaEntity captchaEntity) {
+        String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(captchaEntity.getUuid(), "");
+        String captcha = redisCache.getCacheObject(verifyKey);
+        redisCache.deleteObject(verifyKey);
+        if (captcha.equals(captchaEntity.getCode())){
+            return AjaxResult.success("success");
+        }else {
+            return AjaxResult.error("验证码校验错误");
+        }
+    }
 }

+ 2 - 2
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -111,11 +111,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
-                .antMatchers("/login", "/register", "/captchaImage").permitAll()
+                .antMatchers("/login", "/register", "/captchaImage", "/captchaCheck").permitAll()
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
-                .antMatchers("/system/contract/getInfoByCode").anonymous()
+                .antMatchers("/system/contract/getInfoByCode").permitAll()
                 // 除上面外的所有请求全部需要鉴权认证
                 .anyRequest().authenticated()
                 .and()

+ 1 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java

@@ -138,4 +138,5 @@ public class SysLoginService
         sysUser.setLoginDate(DateUtils.getNowDate());
         userService.updateUserProfile(sysUser);
     }
+
 }

+ 2 - 7
ruoyi-system/src/main/java/com/ruoyi/system/controller/ContractTableController.java

@@ -4,7 +4,6 @@ import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
 import com.ruoyi.system.domain.dto.QueryEntity;
-import com.ruoyi.system.utils.CaptchaUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -38,6 +37,7 @@ public class ContractTableController extends BaseController
     @Autowired
     private IContractTableService contractTableService;
 
+
     /**
      * 查询B类列表
      */
@@ -80,12 +80,7 @@ public class ContractTableController extends BaseController
     @PostMapping("/getInfoByCode")
     public AjaxResult getInfoByCode(@RequestBody QueryEntity queryEntity)
     {
-        CaptchaUtils utils = new CaptchaUtils();
-        if (utils.validateCaptcha(queryEntity.getCode(), queryEntity.getUuid())){
-            return success(contractTableService.selectContractTableByQuery(queryEntity));
-        }else {
-            return error("验证码输入错误");
-        }
+        return success(contractTableService.selectContractTableByQuery(queryEntity));
     }
 
     /**

+ 13 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/CaptchaEntity.java

@@ -0,0 +1,13 @@
+package com.ruoyi.system.domain.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class CaptchaEntity {
+    private String code;
+    private String uuid;
+}

+ 0 - 2
ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/QueryEntity.java

@@ -9,7 +9,5 @@ import lombok.NoArgsConstructor;
 @NoArgsConstructor
 public class QueryEntity {
     private String certNumber; //证书编号
-    private String code; //验证码
     private String userName;  //姓名
-    private String uuid;//验证吗的uuid
 }

+ 0 - 22
ruoyi-system/src/main/java/com/ruoyi/system/utils/CaptchaUtils.java

@@ -1,22 +0,0 @@
-package com.ruoyi.system.utils;
-
-import com.ruoyi.common.constant.CacheConstants;
-import com.ruoyi.common.core.redis.RedisCache;
-import com.ruoyi.common.utils.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-
-public class CaptchaUtils {
-    @Autowired
-    private RedisCache redisCache;
-
-    public Boolean validateCaptcha(String code, String uuid) {
-        String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
-        String captcha = redisCache.getCacheObject(verifyKey);
-        redisCache.deleteObject(verifyKey);
-        if (captcha.equals(code)){
-            return true;
-        }else {
-            return false;
-        }
-    }
-}