feat: SensitiveWords filter

main
wangqing 11 months ago
parent 980a52a062
commit e3dcfd69c0

@ -281,6 +281,10 @@ public class CommentController extends BaseController {
return Result.unauthorized(null);
}
String userId = userLoginDto.getUserId();
String content =sensitiveWordBs.findFirst(commentVo.getContent());
if (StringUtils.isNotEmpty(content)) {
return Result.forbidden(StatusCode.USER_SENSITIVE_INFO);
}
Comment comment = new Comment();
BeanUtils.copyProperties(commentVo, comment);
comment.setUserId(userId);
@ -426,16 +430,16 @@ public class CommentController extends BaseController {
}
@PostMapping("/testSensitiveMosaic/{note}")
public Result testSensitiveMosaic(@PathVariable String note) {
// List<String> all = sensitiveWordBs.findAll(note);
// String all = SensitiveWordHelper.replace(note,mySensitiveWordReplaceUtils);
String all = sensitiveWordBs.replace(note,mySensitiveWordReplaceUtils);
return Result.success(all);
}
//
// @PostMapping("/testSensitiveMosaic/{note}")
// public Result testSensitiveMosaic(@PathVariable String note) {
//
//// List<String> all = sensitiveWordBs.findAll(note);
//// String all = SensitiveWordHelper.replace(note,mySensitiveWordReplaceUtils);
//
// String all = sensitiveWordBs.replace(note,mySensitiveWordReplaceUtils);
// return Result.success(all);
// }
}

@ -18,7 +18,8 @@ public enum StatusCode implements IErrorCode {
USER_IMAGE_VERIFICATION_CODE_MISMATCH(10005, "图形验证码校验失败,请输入正确的验证码"),
USER_NICK_NAME_HAS_BEEN_EXIST(10006, "昵称已经存在"),
USER_INVALID_USER_ID(10007, "无效用户id"),
USER_SENSITIVE_INFO(10008, "不能提交敏感信息"),
// music 模块错误码以20XXX不足5位补0;
MUSIC_COMMON_FAILED(20000, "歌曲模块错误"),
@ -27,7 +28,8 @@ public enum StatusCode implements IErrorCode {
COMMENT_COMMON_FAILED(30000, "评论模块错误"),
COMMENT_REPEAT_SUBMIT(30001, "评论重复提交"),
COMMENT_REPEAT_THUMBUP(30002,"不能重复点赞"),
COMMENT_SENSITIVE_INFO(30004,"不能提交敏感内容"),
// friend 模块错误码以40XXX不足5位补0;
FRIEND_COMMON_FAILED(40000, "交友模块错误"),
FRIEND_CAN_NOT_REPEAT_ADD_FRIEND(40001, "不能重复添加好友"),

@ -12,9 +12,11 @@ import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.luoo.user.dto.TotalCommentVo;
import com.luoo.user.pojo.*;
import com.luoo.user.service.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -91,6 +93,9 @@ public class MyController extends BaseController {
@Autowired
private RabbitTemplate rabbitTemplate;
@Autowired
private SensitiveWordBs sensitiveWordBs;
public static String USER_AVATAR_DIRECTORY = "user/avatar/";
public static String USER_FEEDBACK_IMAGE_DIRECTORY = "user/feedback/";
@ -113,11 +118,18 @@ public class MyController extends BaseController {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
String nickName = userInfoUpdateDto.getNickName();
String result = sensitiveWordBs.findFirst(nickName);
if (StringUtils.isNotEmpty(result)) {
return Result.failed(StatusCode.USER_SENSITIVE_INFO);
}
if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickName())) {
long count = userInfoService.countByNickName(nickName);
if (count > 0) {
return Result.failed(StatusCode.USER_NICK_NAME_HAS_BEEN_EXIST);
}
}
if (!StringTools.isEmpty(nickName)) {
@ -125,6 +137,10 @@ public class MyController extends BaseController {
rabbitTemplate.convertAndSend("userInfoCommentCache",userLoginDto.getUserId());
}
if (!StringTools.isEmpty(userInfoUpdateDto.getSignature())) {
String signature = sensitiveWordBs.findFirst(userInfoUpdateDto.getSignature());
if(StringUtils.isNotEmpty(signature)) {
return Result.failed(StatusCode.USER_SENSITIVE_INFO);
}
user.setSignature(userInfoUpdateDto.getSignature());
}
if (!StringTools.isEmpty(userInfoUpdateDto.getBirthDay())) {

Loading…
Cancel
Save