From 9b28b730f1123ac955a80ec411132cb0885780d8 Mon Sep 17 00:00:00 2001 From: xmzhao71 Date: Wed, 25 Oct 2023 18:51:51 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E4=BF=AE=E6=94=B9=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=AA=8C=E8=AF=81=E7=A0=81=E6=A0=A1=E9=AA=8C=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/sys/HomeController.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/suimangAdmin/src/main/java/com/iformall/controller/sys/HomeController.java b/suimangAdmin/src/main/java/com/iformall/controller/sys/HomeController.java index 33333c1..a524769 100644 --- a/suimangAdmin/src/main/java/com/iformall/controller/sys/HomeController.java +++ b/suimangAdmin/src/main/java/com/iformall/controller/sys/HomeController.java @@ -87,7 +87,9 @@ public class HomeController extends BaseController { //生成图片验证码 BufferedImage image = producer.createImage(text); //保存到shiro session - ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text); +// ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text); + String key = Constant.captchaPrev + ":" + getIpAddr(); + RedisCacheUtils.cache(redisTemplate, key, text, 60); logger.info("验证码接口-生成的验证码:{}", text); ServletOutputStream out = response.getOutputStream(); @@ -100,17 +102,26 @@ public class HomeController extends BaseController { public ResultData login(@RequestBody MallUserInfo user, HttpServletResponse response) { String ipaddress = getIpAddr(); logger.debug("[" + ipaddress + "] HomeController::doLogin"); - try { - String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY); - logger.info("登录接口-验证码:{}", user.getCaptcha()); - logger.info("登录接口-生成的验证码:{}", kaptcha); - if(!user.getCaptcha().equalsIgnoreCase(kaptcha)){ - return new ResultData(ErrorCode.KAPCHA_NOT_EQUAL); - } - } catch (MallinkException e) { - logger.error("验证码" + e.getMessage()); - return new ResultData(ErrorCode.KAPCHA_NOT_VALID.getCode(), e.getMessage()); +// try { +// String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY); +// logger.info("登录接口-验证码:{}", user.getCaptcha()); +// logger.info("登录接口-生成的验证码:{}", kaptcha); +// if(!user.getCaptcha().equalsIgnoreCase(kaptcha)){ +// return new ResultData(ErrorCode.KAPCHA_NOT_EQUAL); +// } +// } catch (MallinkException e) { +// logger.error("验证码" + e.getMessage()); +// return new ResultData(ErrorCode.KAPCHA_NOT_VALID.getCode(), e.getMessage()); +// } + String key = Constant.captchaPrev + ":" + getIpAddr(); + String code = RedisCacheUtils.getCacheString(redisTemplate, key); + if (StringUtils.isBlank(code)) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期"); } + if (!code.equals(user.getCaptcha())) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确"); + } + if (StringUtils.isBlank(user.getUsername()) || StringUtils.isBlank(user.getPassword())) { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);