This commit is contained in:
777
2025-12-08 10:02:10 +08:00
parent 513954ccf1
commit a71249ed12
10 changed files with 105 additions and 37 deletions

View File

@@ -100,11 +100,6 @@ public class CaiLoginManager {
public String login(String username,String password){
String clientIP = ServletUtils.getClientIP();
Boolean b = ipBlackService.checkIp(clientIP);
if(b){
log.error("登录拦截了异常IP={}", clientIP);
throw new ServiceException("40305");
}
User user = userService.getByUsername(username);
if(user == null){
throw new ServiceException("用户不存在或密码错误");
@@ -148,7 +143,8 @@ public class CaiLoginManager {
throw new ServiceException(error);
}else{
String error = String.format("密码错误,已错误%s次还剩%s次", num, passwordMaxNum-num);
throw new ServiceException(error);
// throw new ServiceException(error);
throw new ServiceException("用户不存在或密码错误");
}
}
redissonClient.getAtomicLong(key).delete();
@@ -164,17 +160,17 @@ public class CaiLoginManager {
}
public String register(CaiRegisterUser caiUser) {
User user = userService.getByUsername(caiUser.getUsername());
if(user != null){
throw new ServiceException("手机号已存在");
}
if(!caiUser.getPassword().equals(caiUser.getPasswordCheck())){
throw new ServiceException("两次输入密码不一致,请检查");
}
User user = userService.getByUsername(caiUser.getUsername());
if(user != null){
throw new ServiceException("手机号已存在或验证码错误");
}
if(!caiUser.isSystemOp()){
boolean check = smsVerifyService.check(CodeEnum.REGISTER, caiUser.getUsername(), caiUser.getCode());
if(!check){
throw new ServiceException("验证码错误");
throw new ServiceException("手机号已存在或验证码错误");
}
}
// 加锁
@@ -383,13 +379,13 @@ public class CaiLoginManager {
}
public void resetPassword(ResetPasswordReq code) {
User user = userService.getByUsername(code.getMobile());
if(user == null){
throw new ServiceException("账户不存在");
}
boolean check = smsVerifyService.check(CodeEnum.RESET_PASSWORD, code.getMobile(), code.getCode());
if(!check){
throw new ServiceException("验证码错误");
throw new ServiceException("账户不存在或验证码错误");
}
User user = userService.getByUsername(code.getMobile());
if(user == null){
throw new ServiceException("账户不存在或验证码错误");
}
userService.resetPassword(user.getId(),code.getPassword());
}

View File

@@ -12,6 +12,9 @@ import lombok.Setter;
*/
@Getter
public enum SystemConfigEnum {
OPEN_IP_NUMBER("5", "IP每日登录次数超过多少次封",SystemConfigGroupEnum.BUSINESS),
OPEN_IP_AUTO("1", "开启自动定时封IP",SystemConfigGroupEnum.BUSINESS),
OPEN_RESET_PASSWORD("1", "开启重置密码",SystemConfigGroupEnum.BUSINESS, new BooleanSystemConfigCheck()),
TD_KF("", "土豆客服账号",SystemConfigGroupEnum.BUSINESS),
RANK_LOVE_DAY_AWARD("13800,10800,8800,5800,3800,2800,2800,2800,2800,2800,2800", "魅力榜日榜前10名奖励", SystemConfigGroupEnum.BUSINESS, new NumberListSystemConfigCheck(10)),
RANK_LOVE_WEEK_AWARD("88800,58800,38800,28800,18800,13800,13800,13800,13800,13800,13800,13800", "魅力榜周榜前10名奖励",SystemConfigGroupEnum.BUSINESS, new NumberListSystemConfigCheck(10)),
@@ -132,7 +135,7 @@ public enum SystemConfigEnum {
SYSTEM_CUSTOMER_SERVICE("2,4", "系统客服",SystemConfigGroupEnum.SYSTEM),
PRIVACY_AGREEMENT("/#/agreement/privacy", "隐私协议地址",SystemConfigGroupEnum.SYSTEM),
USER_AGREEMENT("/#/agreement/user", "用户协议地址",SystemConfigGroupEnum.SYSTEM),
OPEN_OLD_REGISTER_CODE("1", "是否开启无验证码注册接口",SystemConfigGroupEnum.SYSTEM, new BooleanSystemConfigCheck()),
OPEN_OLD_REGISTER_CODE("0", "是否开启无验证码注册接口",SystemConfigGroupEnum.SYSTEM, new BooleanSystemConfigCheck()),
ANCHOR_JOIN_AGREEMENT("/#/agreement/anchor-join", "主播入驻协议地址",SystemConfigGroupEnum.SYSTEM),
PAY_CUSTOM("", "支付定向测试",SystemConfigGroupEnum.SYSTEM),
WS_SOCKET_URL("ws://localhost:8080/ws?token=%s&room_id=%s", "ws通讯地址",SystemConfigGroupEnum.SYSTEM),

View File

@@ -2,6 +2,9 @@ package com.ruoyi.cai.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.cai.domain.IpBlack;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDate;
/**
* ip黑名单Mapper接口
@@ -11,4 +14,5 @@ import com.ruoyi.cai.domain.IpBlack;
*/
public interface IpBlackMapper extends BaseMapper<IpBlack> {
int refreshIp(@Param("ipNumber") Integer ipNumber, @Param("now") LocalDate now);
}

View File

@@ -67,7 +67,7 @@ public class YunxinWsServiceV2 {
ImVideoR<ImVideoData> res = ImVideoR.ok(data);
YxDataR<SendMsgResp> r = yunxin.sendToUserNotice(toUid, fromUid, res);
if(r == null || !r.isSuccess()){
log.error("云信发送失败【sendCallAsync】r={}", JSON.toJSONString(r));
log.error("云信发送失败【sendToCallNotify】r={}", JSON.toJSONString(r));
}
});
}

View File

@@ -13,5 +13,7 @@ public interface IpBlackService extends IService<IpBlack> {
Boolean checkIp(String clientIP);
void checkIpThrowException(String clientIP);
void saveIp(IpBlack ipBlack);
}

View File

@@ -7,6 +7,7 @@ import com.ruoyi.cai.mapper.IpBlackMapper;
import com.ruoyi.cai.service.IpBlackService;
import com.ruoyi.common.exception.ServiceException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
@@ -17,6 +18,7 @@ import org.springframework.stereotype.Service;
*/
@RequiredArgsConstructor
@Service
@Slf4j
public class IpBlackServiceImpl extends ServiceImpl<IpBlackMapper,IpBlack> implements IpBlackService {
@Override
@@ -26,6 +28,15 @@ public class IpBlackServiceImpl extends ServiceImpl<IpBlackMapper,IpBlack> imple
return exists;
}
@Override
public void checkIpThrowException(String clientIP){
Boolean b = this.checkIp(clientIP);
if(b){
log.error("登录拦截了异常IP={}", clientIP);
throw new ServiceException("40305");
}
}
@Override
public void saveIp(IpBlack ipBlack){
boolean exists = this.exists(Wrappers.lambdaQuery(IpBlack.class).eq(IpBlack::getIpAddr, ipBlack.getIpAddr()));

View File

@@ -21,6 +21,7 @@ import com.ruoyi.cai.service.UserService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.ServletUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,6 +39,7 @@ import java.util.stream.Collectors;
* @date 2024-01-01
*/
@Service
@Slf4j
public class SmsVerifyServiceImpl extends ServiceImpl<SmsVerifyMapper,SmsVerify> implements SmsVerifyService {
@Autowired
@@ -85,28 +87,20 @@ public class SmsVerifyServiceImpl extends ServiceImpl<SmsVerifyMapper,SmsVerify>
}
}else if(codeEnum == CodeEnum.RESET_PASSWORD){
Long userId = LoginHelper.getUserId();
MinUser miniUser = userService.getMinUserById(userId);
if(miniUser == null || !mobile.equalsIgnoreCase(miniUser.getMobile())){
log.error("手机号与登录手机号不一致");
throw new ServiceException("手机号未注册!");
}
long count = userService.count(Wrappers.lambdaQuery(User.class)
.eq(User::getMobile, mobile));
if(count == 0){
throw new ServiceException("手机号未注册!");
}
}else if(codeEnum == CodeEnum.RESET_ADOLESCENT){
Long userId = LoginHelper.getUserId();
MinUser miniUser = userService.getMinUserById(userId);
if(miniUser == null || !mobile.equalsIgnoreCase(miniUser.getMobile())){
log.error("手机号与登录手机号不一致");
throw new ServiceException("手机号未注册!");
}
long count = userService.count(Wrappers.lambdaQuery(User.class)
.eq(User::getMobile, mobile));
if(count == 0){
throw new ServiceException("手机号未注册!");
}
throw new ServiceException("接口关闭,联系客服");
// Long userId = LoginHelper.getUserId();
// MinUser miniUser = userService.getMinUserById(userId);
// long count = userService.count(Wrappers.lambdaQuery(User.class)
// .eq(User::getMobile, mobile));
// if(count == 0){
// throw new ServiceException("手机号未注册!");
// }
}
LocalDateTime now = LocalDateTime.now();
SmsVerify one = this.getOne(Wrappers.lambdaQuery(SmsVerify.class)