增加验证码的开关的功能

This commit is contained in:
jishenghua
2025-09-21 16:31:03 +08:00
parent d3643c2a99
commit ca89353667
4 changed files with 49 additions and 18 deletions

View File

@@ -151,6 +151,26 @@ public class PlatformConfigController extends BaseController {
return res;
}
/**
* 获取是否开启验证码
* @param request
* @return
*/
@GetMapping(value = "/getPlatform/checkcodeFlag")
@ApiOperation(value = "获取是否开启验证码")
public String getPlatformCheckcodeFlag(HttpServletRequest request)throws Exception {
String res;
try {
String platformKey = "checkcode_flag";
PlatformConfig platformConfig = platformConfigService.getInfoByKey(platformKey);
res = platformConfig.getPlatformValue();
} catch(Exception e){
logger.error(e.getMessage(), e);
res = "#";
}
return res;
}
/**
* 根据platformKey更新platformValue
* @param object

View File

@@ -288,24 +288,27 @@ public class UserService {
* @param uuid 唯一标识
* @return 结果
*/
public void validateCaptcha(String code, String uuid) {
if(StringUtil.isNotEmpty(code) && StringUtil.isNotEmpty(uuid)) {
code = code.trim();
uuid = uuid.trim();
String verifyKey = BusinessConstants.CAPTCHA_CODE_KEY + uuid;
String captcha = redisService.getCacheObject(verifyKey);
redisService.deleteObject(verifyKey);
if (captcha == null) {
logger.error("异常码[{}],异常提示[{}]", ExceptionConstants.USER_JCAPTCHA_EXPIRE_CODE, ExceptionConstants.USER_JCAPTCHA_EXPIRE_MSG);
throw new BusinessRunTimeException(ExceptionConstants.USER_JCAPTCHA_EXPIRE_CODE, ExceptionConstants.USER_JCAPTCHA_EXPIRE_MSG);
public void validateCaptcha(String code, String uuid) throws Exception {
PlatformConfig platformConfig = platformConfigService.getInfoByKey("checkcode_flag");
if(platformConfig!=null && "1".equals(platformConfig.getPlatformValue())) {
if(StringUtil.isNotEmpty(code) && StringUtil.isNotEmpty(uuid)) {
code = code.trim();
uuid = uuid.trim();
String verifyKey = BusinessConstants.CAPTCHA_CODE_KEY + uuid;
String captcha = redisService.getCacheObject(verifyKey);
redisService.deleteObject(verifyKey);
if (captcha == null) {
logger.error("异常码[{}],异常提示[{}]", ExceptionConstants.USER_JCAPTCHA_EXPIRE_CODE, ExceptionConstants.USER_JCAPTCHA_EXPIRE_MSG);
throw new BusinessRunTimeException(ExceptionConstants.USER_JCAPTCHA_EXPIRE_CODE, ExceptionConstants.USER_JCAPTCHA_EXPIRE_MSG);
}
if (!code.equalsIgnoreCase(captcha)) {
logger.error("异常码[{}],异常提示[{}]", ExceptionConstants.USER_JCAPTCHA_ERROR_CODE, ExceptionConstants.USER_JCAPTCHA_ERROR_MSG);
throw new BusinessRunTimeException(ExceptionConstants.USER_JCAPTCHA_ERROR_CODE, ExceptionConstants.USER_JCAPTCHA_ERROR_MSG);
}
} else {
logger.error("异常码[{}],异常提示[{}]", ExceptionConstants.USER_JCAPTCHA_EMPTY_CODE, ExceptionConstants.USER_JCAPTCHA_EMPTY_MSG);
throw new BusinessRunTimeException(ExceptionConstants.USER_JCAPTCHA_EMPTY_CODE, ExceptionConstants.USER_JCAPTCHA_EMPTY_MSG);
}
if (!code.equalsIgnoreCase(captcha)) {
logger.error("异常码[{}],异常提示[{}]", ExceptionConstants.USER_JCAPTCHA_ERROR_CODE, ExceptionConstants.USER_JCAPTCHA_ERROR_MSG);
throw new BusinessRunTimeException(ExceptionConstants.USER_JCAPTCHA_ERROR_CODE, ExceptionConstants.USER_JCAPTCHA_ERROR_MSG);
}
} else {
logger.error("异常码[{}],异常提示[{}]", ExceptionConstants.USER_JCAPTCHA_EMPTY_CODE, ExceptionConstants.USER_JCAPTCHA_EMPTY_MSG);
throw new BusinessRunTimeException(ExceptionConstants.USER_JCAPTCHA_EMPTY_CODE, ExceptionConstants.USER_JCAPTCHA_EMPTY_MSG);
}
}