Improving structure / format of the code. 优化gateway.checkCode()验证验证码逻辑

This commit is contained in:
lht 2021-08-04 21:55:58 +08:00
parent 626f559c92
commit 4e73fcdd4b
2 changed files with 4 additions and 6 deletions

View File

@ -22,7 +22,7 @@
| Spring Cloud Alibaba | 2021.1 | | Spring Cloud Alibaba | 2021.1 |
| Spring Security OAuth2 | 2.3.6 | | Spring Security OAuth2 | 2.3.6 |
| Mybatis Plus | 3.4.3 | | Mybatis Plus | 3.4.3 |
| hutool | 5.7.6 | | hutool | 5.7.7 |
| Avue | 2.6.18 | | Avue | 2.6.18 |
### 模块说明 ### 模块说明

View File

@ -17,6 +17,7 @@
package com.pig4cloud.pig.gateway.filter; package com.pig4cloud.pig.gateway.filter;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -121,12 +122,9 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory<Obje
Object codeObj = redisTemplate.opsForValue().get(key); Object codeObj = redisTemplate.opsForValue().get(key);
if (codeObj == null) {
throw new ValidateCodeException("验证码不合法");
}
redisTemplate.delete(key); redisTemplate.delete(key);
if (!code.equals(codeObj)) {
if (ObjectUtil.isEmpty(codeObj) || !code.equals(codeObj)) {
throw new ValidateCodeException("验证码不合法"); throw new ValidateCodeException("验证码不合法");
} }
} }