deason 5 jaren geleden
bovenliggende
commit
0f9124969e

+ 18 - 1
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/VerifyCodeServiceImpl.java

@@ -94,7 +94,21 @@ public class VerifyCodeServiceImpl implements VerifyCodeService {
             throw new StatusException("400", "验证码不能为空");
         }
 
-        // todo
+        final String cacheKeyVerifyCode = String.format(CACHE_KEY_VERIFY_CODE, info.getRootOrgId(), info.getAccountValue());
+        VerifyCodeCacheBean cacheBean = redisClient.get(cacheKeyVerifyCode, VerifyCodeCacheBean.class);
+        if (cacheBean == null) {
+            throw new StatusException("400", "账号不存在或验证码已过期,请重试!");
+        }
+
+        final String cacheKeyVerifyCodeResource = String.format(CACHE_KEY_VERIFY_CODE_RESOURCE, cacheBean.getUuid());
+        Boolean resource = redisClient.get(cacheKeyVerifyCodeResource, Boolean.class);
+        if (resource == null) {
+            throw new StatusException("400", "验证码请求无效,请重试!");
+        }
+
+        if (!info.getVerifyCode().equals(cacheBean.getVerifyCode())) {
+            throw new StatusException("400", "验证码输入不正确,请重试!");
+        }
 
         LoginInfo loginInfo = new LoginInfo();
         loginInfo.setRootOrgId(info.getRootOrgId());
@@ -104,6 +118,9 @@ public class VerifyCodeServiceImpl implements VerifyCodeService {
         loginInfo.setClientIp(info.getClientIp());
         User user = authService.login(loginInfo);
 
+        redisClient.delete(cacheKeyVerifyCode);
+        redisClient.delete(cacheKeyVerifyCodeResource);
+
         if (UserType.STUDENT.equals(user.getUserType())) {
             // 在线学生登录打点
             ReportsUtil.report(new OnlineStudentReport(user.getRootOrgId(), user.getUserId()));