diff --git a/back/services/auth.ts b/back/services/auth.ts index a2a47cd9..849c0c1a 100644 --- a/back/services/auth.ts +++ b/back/services/auth.ts @@ -39,6 +39,17 @@ export default class AuthService { ) { return this.initAuthInfo(); } + if (retries > 2 && Date.now() - lastlogon < Math.pow(3, retries) * 1000) { + return { + code: 410, + message: `失败次数过多,请${Math.round( + (Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000, + )}秒后重试`, + data: Math.round( + (Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000, + ), + }; + } if (username === cUsername && password === cPassword) { const data = createRandomString(50, 100); let token = jwt.sign({ data }, config.secret as any, { @@ -68,20 +79,6 @@ export default class AuthService { lastaddr: address, }), ); - if ( - retries > 2 && - Date.now() - lastlogon < Math.pow(3, retries) * 1000 - ) { - return { - code: 410, - message: `失败次数过多,请${Math.round( - (Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000, - )}秒后重试`, - data: Math.round( - (Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000, - ), - }; - } return { code: 400, message: config.authError }; } } else { diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index d9cc7143..a8046beb 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -107,6 +107,7 @@ const Login = () => { setWaitTime(null)} format="ss" value={Date.now() + 1000 * waitTime} />