Przeglądaj źródła

联通版本加上登录校验

lyhzzz 1 rok temu
rodzic
commit
2becafdf57

+ 1 - 1
src/main/java/com/fdkankan/manage/config/SaTokenConfigure.java

@@ -45,7 +45,7 @@ public class SaTokenConfigure {
     public SaServletFilter getSaServletFilter() {
         return new SaServletFilter()
                 // 指定 拦截路由 与 放行路由
-                .addInclude("/**").addExclude("/**/reMyselfPassword","/**/test/**","/**/inner/**","/**/feedback/h5/**","/**/common/**")
+                .addInclude("/**").addExclude("/**/reMyselfPassword","/**/test/**","/**/inner/**","/**/feedback/h5/**","/**/common/**","/**/getLoginAuthCode/**")
                 // 认证函数: 每次请求执行
                 .setAuth(obj -> {
                     // 登录认证 -- 拦截所有路由,并排除/user/doLogin 用于开放登录

+ 18 - 4
src/main/java/com/fdkankan/manage/controller/LoginController.java

@@ -1,7 +1,8 @@
 package com.fdkankan.manage.controller;
 
-import cn.hutool.captcha.CaptchaUtil;
-import cn.hutool.captcha.LineCaptcha;
+import cn.hutool.captcha.*;
+import cn.hutool.captcha.generator.MathGenerator;
+import cn.hutool.captcha.generator.RandomGenerator;
 import cn.hutool.extra.servlet.ServletUtil;
 import com.dtflys.forest.annotation.BaseRequest;
 import com.fdkankan.manage.common.RedisKeyUtil;
@@ -44,7 +45,9 @@ public class LoginController extends BaseController {
         if(!redisUtil.hasKey(String.format(RedisKeyUtil.loginAuthCode,id))){
             throw new BusinessException(ResultCode.LOGIN_AUTH_NOT_EXIST);
         }
-        if(!redisUtil.get(String.format(RedisKeyUtil.loginAuthCode,id)).equals(param.getAuthCode())){
+        MathGenerator mathGenerator = new MathGenerator(3);
+        boolean verify = mathGenerator.verify(redisUtil.get(String.format(RedisKeyUtil.loginAuthCode,id)),param.getAuthCode());
+        if(!verify){
             throw new BusinessException(ResultCode.LOGIN_AUTH_NOT_EXIST);
         }
 
@@ -68,7 +71,9 @@ public class LoginController extends BaseController {
         response.setContentType("image/jpeg");
         String id = request.getSession().getId();
         try {
-            LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100,4,60);
+            LineCaptcha lineCaptcha = new LineCaptcha(400, 100);
+            MathGenerator mathGenerator = new MathGenerator(3);
+            lineCaptcha.setGenerator(mathGenerator);
             redisUtil.set(String.format(RedisKeyUtil.loginAuthCode,id),lineCaptcha.getCode(),60*5);
             lineCaptcha.write(response.getOutputStream());
             response.getOutputStream().close();
@@ -78,4 +83,13 @@ public class LoginController extends BaseController {
 
     }
 
+    public static void main(String[] args) {
+        LineCaptcha lineCaptcha = new LineCaptcha(400, 100);
+        MathGenerator mathGenerator = new MathGenerator(3);
+        boolean verify = mathGenerator.verify("79 *40 =","3160");
+        System.out.println(verify);
+
+        System.out.println(lineCaptcha.getCode());
+    }
+
 }