diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/app/AppSystemController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/app/AppSystemController.java index 4f2a7058..2c9fe2ac 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/app/AppSystemController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/app/AppSystemController.java @@ -519,7 +519,9 @@ public class AppSystemController extends BaseController { String code = juheAuthenticationDto.getCode(); String username = SecurityUtils.getUsername(); - appvalidateCaptcha(username, code, mobile); + + // 验证短信验证码 + appvalidateCaptchaJuhe(username, code, mobile); Long userId = getUserId(); UserInfo userInfo = userInfoService.selectUserInfoByUserId(userId); @@ -542,6 +544,13 @@ public class AppSystemController extends BaseController { userInfo.setIdCard(idcard); userInfoService.updateUserInfo(userInfo); + // 删除缓存 + // 缓存的验证码和试错次数 + String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + mobile; + String countKey = CacheConstants.CAPTCHA_CODE_KEY_COUNT + mobile; + redisCache.deleteObject(verifyKey); + redisCache.deleteObject(countKey); + return success("实名认证成功"); } @@ -2466,6 +2475,50 @@ public class AppSystemController extends BaseController { } + private void appvalidateCaptchaJuhe(String username, String code, String phone) { + boolean captchaEnabled = configService.selectCaptchaEnabled(); + if (captchaEnabled) { + String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + phone; + String captcha = redisCache.getCacheObject(verifyKey); + + // 尝试次数 + String countKey = CacheConstants.CAPTCHA_CODE_KEY_COUNT + phone; + int captchaCount = redisCache.getCacheObject(countKey); + + if (captcha == null ) { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); + throw new CaptchaDisableException(); + } + + if(captchaCount >= 3){ + // 删除缓存 + redisCache.deleteObject(verifyKey); + redisCache.deleteObject(countKey); + + // 验证码失效 + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); + throw new CaptchaDisableException(); + } + + + if (!code.equalsIgnoreCase(captcha)) + { + + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); + throw new CaptchaException(); + } + // 尝试次数加1 + redisCache.setCacheObject(countKey, captchaCount + 1); +// else{ +// // 登录成功删除验证码 +// redisCache.deleteObject(verifyKey); +// redisCache.deleteObject(countKey); +// } + } + + } + + }