提交 cad0c08c 编写于 作者: D dqjdda

代码优化

上级 bb5cc6f6
......@@ -30,6 +30,9 @@ public class RedisServiceImpl implements RedisService {
@Value("${jwt.online}")
private String onlineKey;
@Value("${jwt.codeKey}")
private String codeKey;
public RedisServiceImpl(RedisTemplate redisTemplate) {
this.redisTemplate = redisTemplate;
}
......@@ -43,7 +46,7 @@ public class RedisServiceImpl implements RedisService {
Set<String> keys = redisTemplate.keys(key);
for (String s : keys) {
// 过滤掉权限的缓存
if (s.contains("role::loadPermissionByUser") || s.contains("user::loadUserByUsername") || s.contains(onlineKey)) {
if (s.contains("role::loadPermissionByUser") || s.contains("user::loadUserByUsername") || s.contains(onlineKey) || s.contains(codeKey)) {
continue;
}
RedisVo redisVo = new RedisVo(s, Objects.requireNonNull(redisTemplate.opsForValue().get(s)).toString());
......@@ -63,7 +66,7 @@ public class RedisServiceImpl implements RedisService {
@Override
public void deleteAll() {
Set<String> keys = redisTemplate.keys( "*");
redisTemplate.delete(keys.stream().filter(s -> !s.contains(onlineKey)).collect(Collectors.toList()));
redisTemplate.delete(keys.stream().filter(s -> !s.contains(onlineKey)).filter(s -> !s.contains(codeKey)).collect(Collectors.toList()));
}
@Override
......
......@@ -38,8 +38,8 @@ import javax.servlet.http.HttpServletRequest;
@Api(tags = "系统:系统授权接口")
public class AuthenticationController {
@Value("${jwt.online}")
private String onlineKey;
@Value("${jwt.codeKey}")
private String codeKey;
private final JwtTokenUtil jwtTokenUtil;
......@@ -104,7 +104,7 @@ public class AuthenticationController {
captcha.setLen(2);
// 获取运算的结果:5
String result = captcha.text();
String uuid = onlineKey + IdUtil.simpleUUID();
String uuid = codeKey + IdUtil.simpleUUID();
redisService.saveCode(uuid,result);
return new ImgResult(captcha.toBase64(),uuid);
}
......
......@@ -49,6 +49,8 @@ jwt:
expiration: 21600000
# 在线用户key
online: online-token
# 验证码
codeKey: code-key
#是否允许生成代码,生产环境设置为false
generator:
......
......@@ -51,6 +51,8 @@ jwt:
expiration: 7200000
# 在线用户key
online: online-token
# 验证码
codeKey: code-key
#是否允许生成代码,生产环境设置为false
generator:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册