From 8c355b6159df33c4d3ae0c9495d941c66c60acd9 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Sun, 22 Aug 2021 12:59:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95=E9=87=8D?= =?UTF-8?q?=E8=AF=95=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/auth.ts | 25 +++++++++++-------------- src/pages/login/index.tsx | 1 + 2 files changed, 12 insertions(+), 14 deletions(-) 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} />