v1.1 注册ip限制-抽去sysConfig配置

This commit is contained in:
2022-10-27 15:25:10 +08:00
parent 3479b869d7
commit b8a82f968b
3 changed files with 55 additions and 12 deletions

View File

@@ -0,0 +1,22 @@
package com.accompany.oauth2.dto;
public class IpMaxRegisterLimitConfig {
private boolean open;
private long max;
public boolean getOpen() {
return open;
}
public void setOpen(boolean open) {
this.open = open;
}
public long getMax() {
return max;
}
public void setMax(long max) {
this.max = max;
}
}

View File

@@ -33,6 +33,7 @@ import com.accompany.core.vo.RedisHashVo;
import com.accompany.core.vo.VisitorVo;
import com.accompany.oauth2.config.OAuthConfig;
import com.accompany.oauth2.constant.OAuthStatus;
import com.accompany.oauth2.dto.IpMaxRegisterLimitConfig;
import com.accompany.oauth2.event.UserRegisterSuccessEvent;
import com.accompany.oauth2.exception.CustomOAuth2Exception;
import com.accompany.oauth2.exception.MyServiceException;
@@ -92,9 +93,6 @@ public class AccountManageService {
@Autowired
private AccountProtectRecordService accountProtectRecordService;
@Autowired
private SmsService smsService;
@Autowired
private UsersBaseService usersBaseService;
@@ -147,10 +145,14 @@ public class AccountManageService {
}
Account account = accountService.getAccountByThird(type, unionId);
if (account == null) {
int count = accountService.getRegisterIpCountByOneDay(ipAddress);
if (count > maxRegisterCount) {
throw new CustomOAuth2Exception(CustomOAuth2Exception.SIGN_IP_TO_OFTEN, "注册过于频繁");
IpMaxRegisterLimitConfig config = getLimitConfig();
if (null != config && config.getOpen()){
int count = accountService.getRegisterIpCountByOneDay(ipAddress);
if (count > config.getMax()) {
throw new CustomOAuth2Exception(CustomOAuth2Exception.SIGN_IP_TO_OFTEN, "注册过于频繁");
}
}
Date date = new Date();
account = new Account();
account.setNeteaseToken(UUIDUitl.get());
@@ -329,9 +331,12 @@ public class AccountManageService {
*/
public Account saveSignUpByPhone(String phone, String password, DeviceInfo deviceInfo, String prefillInviteCode, Long prefillInviteUid,
String ipAddress) throws Exception {
int count = accountService.getRegisterIpCountByOneDay(ipAddress);
if (count > maxRegisterCount) {
throw new CustomOAuth2Exception(CustomOAuth2Exception.SIGN_IP_TO_OFTEN, "注册过于频繁");
IpMaxRegisterLimitConfig config = getLimitConfig();
if (null != config && config.getOpen()){
int count = accountService.getRegisterIpCountByOneDay(ipAddress);
if (count > config.getMax()) {
throw new CustomOAuth2Exception(CustomOAuth2Exception.SIGN_IP_TO_OFTEN, "注册过于频繁");
}
}
Date date = new Date();
Account account = new Account();
@@ -785,9 +790,12 @@ public class AccountManageService {
*/
public Account register(String ipAddress, DeviceInfo deviceInfo, int type, String openid, String unionId,
String phone) throws Exception {
int count = accountService.getRegisterIpCountByOneDay(ipAddress);
if (count > maxRegisterCount) {
throw new CustomOAuth2Exception(CustomOAuth2Exception.SIGN_IP_TO_OFTEN, "注册过于频繁");
IpMaxRegisterLimitConfig config = getLimitConfig();
if (null != config && config.getOpen()){
int count = accountService.getRegisterIpCountByOneDay(ipAddress);
if (count > config.getMax()) {
throw new CustomOAuth2Exception(CustomOAuth2Exception.SIGN_IP_TO_OFTEN, "注册过于频繁");
}
}
//第三方注册保护
//checkRegisterProtected(yiDunDto, shuMeiDto, type, unionId, openid);
@@ -873,6 +881,15 @@ public class AccountManageService {
jedisService.setex(RedisKey.cancel_user_recover_credentials.getKey(String.valueOf(users.getErbanNo())), surviveTime, String.valueOf(uid));
throw exception;
}
private IpMaxRegisterLimitConfig getLimitConfig(){
String config = sysConfService.getSysConfValueById(Constant.SysConfId.IP_MAX_REGISTER_LIMIT_CONFIG);
if (StringUtils.isEmpty(config)){
return null;
}
return gson.fromJson(config, IpMaxRegisterLimitConfig.class);
}
}