From 3d0ca23f6e3cbf81f249472c51e5c1667d3bf501 Mon Sep 17 00:00:00 2001 From: Gary Date: Mon, 18 Mar 2024 10:21:56 +0800 Subject: [PATCH] 1.remove redisMobileCheckCodeKey in case login success --- .../luoo/user/controller/LoginController.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java index caac4b3..42da70b 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java @@ -103,23 +103,21 @@ public class LoginController extends BaseController { @VerifyParam LoginReq loginReq) { // 得到缓存中的验证码 String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + loginReq.getDeviceId(); - try { - String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey); - if (StringTools.isEmpty(redisMobileCheckCode)) { - return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED); - } - if (!redisMobileCheckCode.equals(loginReq.getMobileCheckCode())) { - return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); - } - UserInfo loginUserInfo = new UserInfo(); - loginUserInfo.setMobile(loginReq.getMobile()); - loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId()); - loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand()); - loginUserInfo.setLastLoginIp(getIpAddr(request)); - return Result.success(userInfoService.loginOrRegister(loginUserInfo)); - } finally { - redisTemplate.delete(redisMobileCheckCodeKey); + String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey); + if (StringTools.isEmpty(redisMobileCheckCode)) { + return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED); + } + if (!redisMobileCheckCode.equals(loginReq.getMobileCheckCode())) { + return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); } + UserInfo loginUserInfo = new UserInfo(); + loginUserInfo.setMobile(loginReq.getMobile()); + loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId()); + loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand()); + loginUserInfo.setLastLoginIp(getIpAddr(request)); + String token = userInfoService.loginOrRegister(loginUserInfo); + redisTemplate.delete(redisMobileCheckCodeKey); + return Result.success(token); } /**