perf:优化登录次数校验

This commit is contained in:
曾文豪
2024-12-08 11:53:11 +08:00
parent 690dffa779
commit a987689bd6
2 changed files with 17 additions and 4 deletions

View File

@@ -43,9 +43,12 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
*/
public TokenBean login(DoLoginInfo loginInfo) {
int loginErrorTimes = coreLogLoginMapper.getLoginErrorTimes(loginInfo.getLoginIp());
if (loginErrorTimes > 4) {
throw new ApiException("登录失败已达5次请10分钟后再试");
int loginErrorTimes = tsLoginConfigurer.getLoginErrorTimes();
if (loginErrorTimes > 0) {
int currentErrorTimes = coreLogLoginMapper.getLoginErrorTimes(loginInfo.getLoginIp());
if (currentErrorTimes >= loginErrorTimes) {
throw new ApiException("登录失败已达" + loginErrorTimes + "请10分钟后再试");
}
}
CorePlatformUnique platformUnique = getOneByColumn("unique_id", loginInfo.getUnique());

View File

@@ -36,7 +36,7 @@ public interface TsLoginConfigurer {
/**
* 登录失败的时候
*/
default void onLoginError(String to,HttpServletResponse response) {
default void onLoginError(String to, HttpServletResponse response) {
ServletKit.write(response, "404", "text");
}
@@ -66,4 +66,14 @@ public interface TsLoginConfigurer {
*/
RequestUserInfo getCurrentUserName(TokenBean userId);
/**
* 获取登录失败的次数默认5次
*
* @return
*/
default int getLoginErrorTimes() {
return 0;
}
}