修复登录重试判断

This commit is contained in:
hanhh 2021-08-22 12:59:34 +08:00
parent 622037ee98
commit 8c355b6159
2 changed files with 12 additions and 14 deletions

View File

@ -39,6 +39,17 @@ export default class AuthService {
) { ) {
return this.initAuthInfo(); 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) { if (username === cUsername && password === cPassword) {
const data = createRandomString(50, 100); const data = createRandomString(50, 100);
let token = jwt.sign({ data }, config.secret as any, { let token = jwt.sign({ data }, config.secret as any, {
@ -68,20 +79,6 @@ export default class AuthService {
lastaddr: address, 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 }; return { code: 400, message: config.authError };
} }
} else { } else {

View File

@ -107,6 +107,7 @@ const Login = () => {
<Countdown <Countdown
valueStyle={{ color: 'rgba(232, 230, 227, 0.25)' }} valueStyle={{ color: 'rgba(232, 230, 227, 0.25)' }}
className="inline-countdown" className="inline-countdown"
onFinish={() => setWaitTime(null)}
format="ss" format="ss"
value={Date.now() + 1000 * waitTime} value={Date.now() + 1000 * waitTime}
/> />