This commit is contained in:
2023-08-07 09:46:32 +08:00
parent 1be342922f
commit 9dece605ca
3 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package com.qiaoba.auth.service.impl;
import cn.hutool.captcha.generator.MathGenerator;
import cn.hutool.core.util.StrUtil;
import com.qiaoba.api.auth.service.AuthConfigApiService;
import com.qiaoba.api.auth.constants.SecurityConstant;
@ -69,7 +70,7 @@ public class AuthConfigServiceImpl implements AuthConfigApiService {
if (StrUtil.isBlank(realCode)) {
throw new ServiceException("验证码已经过期失效!");
} else {
if (!code.equalsIgnoreCase(realCode)) {
if (!new MathGenerator().verify(realCode, code)) {
throw new ServiceException("验证码输入错误!");
}
}

View File

@ -2,6 +2,7 @@ package com.qiaoba.auth.service.impl;
import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.MathGenerator;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.ObjectUtil;
@ -66,7 +67,11 @@ public class SysLoginServiceImpl implements SysLoginService {
}
String uuid = UUID.randomUUID().toString(true);
LineCaptcha captcha = CaptchaUtil.createLineCaptcha(150, 50, 4, 20);
LineCaptcha captcha = CaptchaUtil.createLineCaptcha(150, 50, 4, 0);
// 自定义验证码内容为四则运算方式
captcha.setGenerator(new MathGenerator(1));
// 重新生成code
captcha.createCode();
map.put("uuid", uuid);
map.put("img", captcha.getImageBase64());
redisService.set(SecurityConstant.CAPTCHA_KEY + uuid, captcha.getCode(), 120);

View File

@ -53,12 +53,14 @@ public class SysConfigServiceImpl implements SysConfigService {
@Override
public int updateById(SysConfig sysConfig) {
checkKeyIsExist(sysConfig);
String configKey = sysConfig.getConfigKey();
// key 禁止修改
sysConfig.setConfigKey(null);
sysConfig.setUpdateTime(new Date());
sysConfig.setUpdateUser(SecurityUtil.getLoginUsername());
int result = sysConfigMapper.updateById(sysConfig);
if (result > BaseConstant.HANDLE_ERROR) {
sysConfig.setConfigKey(configKey);
cacheConfig(sysConfig);
}
return result;