Browse Source

#IBY0OL 长时间未操作,验证码无法登录

MaxKey 2 weeks ago
parent
commit
ca2832d4e2

+ 4 - 3
maxkey-starter/maxkey-starter-captcha/src/main/java/org/dromara/maxkey/web/contorller/ImageCaptchaEndpoint.java

@@ -78,10 +78,11 @@ public class ImageCaptchaEndpoint {
                 }
             }
             String kaptchaKey = "";
-            if(StringUtils.isNotBlank(state) 
-            		&& !state.equalsIgnoreCase("state")
-            		&& authTokenService.validateJwtToken(state)) {
+            if(StringUtils.isNotBlank(state) && !state.equalsIgnoreCase("state")) {
             	//just validate state Token
+            	if(!authTokenService.validateJwtToken(state)) {
+            		return new Message<>(Message.FAIL,"JwtToken is not Validate  ");
+            	}
             }else {
             	state = authTokenService.genRandomJwt();
             }

+ 8 - 6
maxkey-web-frontend/maxkey-web-app/src/app/routes/passport/login/login.component.ts

@@ -140,10 +140,7 @@ export class UserLoginComponent implements OnInit, OnDestroy {
               this.form.get('captcha')?.clearValidators();
             } else {
               //init image captcha
-              this.imageCaptchaService.captcha({ state: this.state, captcha: this.captchaType }).subscribe(res => {
-                this.imageCaptcha = res.data.image;
-                this.cdr.detectChanges();
-              });
+              this.getImageCaptcha();
             }
           }
         }
@@ -206,8 +203,13 @@ export class UserLoginComponent implements OnInit, OnDestroy {
   // #region get captcha
   getImageCaptcha(): void {
     this.imageCaptchaService.captcha({ state: this.state, captcha: this.captchaType }).subscribe(res => {
-      this.imageCaptcha = res.data.image;
-      this.cdr.detectChanges();
+      if (res.code == 0) {
+        this.imageCaptcha = res.data.image;
+        this.cdr.detectChanges();
+      } else {
+        //令牌失效时,重新刷新页面
+        window.location.reload();
+      }
     });
   }
 

+ 8 - 6
maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/passport/login/login.component.ts

@@ -99,10 +99,7 @@ export class UserLoginComponent implements OnInit, OnDestroy {
           this.state = res.data.state;
           this.captchaType = res.data.captcha;
           //init image captcha
-          this.imageCaptchaService.captcha({ state: this.state, captcha: this.captchaType }).subscribe(res => {
-            this.imageCaptcha = res.data.image;
-            this.cdr.detectChanges();
-          });
+          this.getImageCaptcha();
         }
       });
   }
@@ -113,8 +110,13 @@ export class UserLoginComponent implements OnInit, OnDestroy {
 
   getImageCaptcha(): void {
     this.imageCaptchaService.captcha({ state: this.state, captcha: this.captchaType }).subscribe(res => {
-      this.imageCaptcha = res.data.image;
-      this.cdr.detectChanges();
+      if (res.code === 0) {
+        this.imageCaptcha = res.data.image;
+        this.cdr.detectChanges();
+      } else {
+        //令牌失效时,重新刷新页面
+        window.location.reload();
+      }
     });
   }