mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
修复登录验证
This commit is contained in:
parent
98c2a37ab6
commit
ad47277149
|
@ -65,15 +65,13 @@ export default class UserService {
|
||||||
return this.initAuthInfo();
|
return this.initAuthInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retries > 2 && Date.now() - lastlogon < Math.pow(3, retries) * 1000) {
|
const retriesTime = Math.pow(3, retries) * 1000;
|
||||||
|
if (retries > 2 && timestamp - lastlogon < retriesTime) {
|
||||||
|
const waitTime = Math.ceil((retriesTime - (timestamp - lastlogon)) / 1000);
|
||||||
return {
|
return {
|
||||||
code: 410,
|
code: 410,
|
||||||
message: `失败次数过多,请${Math.round(
|
message: `失败次数过多,请${waitTime}秒后重试`,
|
||||||
(Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000,
|
data: waitTime,
|
||||||
)}秒后重试`,
|
|
||||||
data: Math.round(
|
|
||||||
(Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000,
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +88,7 @@ export default class UserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = createRandomString(50, 100);
|
const data = createRandomString(50, 100);
|
||||||
const expiration = twoFactorActivated ? 30 : 3;
|
const expiration = twoFactorActivated ? 60 : 20;
|
||||||
let token = jwt.sign({ data }, config.secret as any, {
|
let token = jwt.sign({ data }, config.secret as any, {
|
||||||
expiresIn: 60 * 60 * 24 * expiration,
|
expiresIn: 60 * 60 * 24 * expiration,
|
||||||
algorithm: 'HS384',
|
algorithm: 'HS384',
|
||||||
|
@ -111,8 +109,7 @@ export default class UserService {
|
||||||
});
|
});
|
||||||
await this.notificationService.notify(
|
await this.notificationService.notify(
|
||||||
'登录通知',
|
'登录通知',
|
||||||
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${
|
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${req.platform
|
||||||
req.platform
|
|
||||||
}端 登录成功,ip地址 ${ip}`,
|
}端 登录成功,ip地址 ${ip}`,
|
||||||
);
|
);
|
||||||
await this.getLoginLog();
|
await this.getLoginLog();
|
||||||
|
@ -140,8 +137,7 @@ export default class UserService {
|
||||||
});
|
});
|
||||||
await this.notificationService.notify(
|
await this.notificationService.notify(
|
||||||
'登录通知',
|
'登录通知',
|
||||||
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${
|
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${req.platform
|
||||||
req.platform
|
|
||||||
}端 登录失败,ip地址 ${ip}`,
|
}端 登录失败,ip地址 ${ip}`,
|
||||||
);
|
);
|
||||||
await this.getLoginLog();
|
await this.getLoginLog();
|
||||||
|
@ -155,8 +151,17 @@ export default class UserService {
|
||||||
status: LoginStatus.fail,
|
status: LoginStatus.fail,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
if (retries > 2) {
|
||||||
|
const waitTime = Math.round(Math.pow(3, retries + 1));
|
||||||
|
return {
|
||||||
|
code: 410,
|
||||||
|
message: `失败次数过多,请${waitTime}秒后重试`,
|
||||||
|
data: waitTime,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
return { code: 400, message: config.authError };
|
return { code: 400, message: config.authError };
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return this.initAuthInfo();
|
return this.initAuthInfo();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user