提交 cad0c08c 编写于 作者: D dqjdda

代码优化

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