提交 e22af215 编写于 作者: 智布道's avatar 智布道 👁

🐛 优化前台发布评论的代码,解决iphone端右上角菜单无法点出的问题(感谢lzhpo同学)

上级 2c557116
......@@ -2,8 +2,6 @@ package com.zyd.blog.controller;
import com.zyd.blog.business.annotation.BussinessLog;
import com.zyd.blog.business.enums.FileUploadType;
import com.zyd.blog.business.service.BizArticleService;
import com.zyd.blog.business.service.SysConfigService;
import com.zyd.blog.core.websocket.server.ZydWebsocketServer;
import com.zyd.blog.core.websocket.util.WebSocketUtil;
import com.zyd.blog.file.FileUploader;
......@@ -36,10 +34,6 @@ import java.util.Map;
@RequestMapping("/api")
public class RestApiController {
@Autowired
private BizArticleService articleService;
@Autowired
private SysConfigService configService;
@Autowired
private ZydWebsocketServer websocketServer;
......
......@@ -22,7 +22,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(rememberAuthenticationInterceptor)
.excludePathPatterns("/passport/**", "/error/**", "/assets/**", "/getKaptcha/**", "favicon.ico")
.excludePathPatterns("/passport/**", "/error/**", "/assets/**", "/getKaptcha/**", "/websocket", "favicon.ico")
.addPathPatterns("/**");
}
}
......@@ -147,36 +147,50 @@ public class BizCommentServiceImpl implements BizCommentService {
@RedisCache(flush = true)
public Comment comment(Comment comment) throws ZhydCommentException {
SysConfig sysConfig = configService.getByKey(ConfigKeyEnum.ANONYMOUS.getKey());
boolean anonymous = true;
if (null != sysConfig) {
String anonymous = sysConfig.getConfigValue();
if (!StringUtils.isEmpty(anonymous) && !"1".equals(anonymous) && !SessionUtil.isLogin()) {
throw new ZhydCommentException("站长已关闭匿名评论,请先登录!");
}
anonymous = Boolean.valueOf(sysConfig.getConfigValue());
}
// 非匿名且未登录
if (!anonymous && !SessionUtil.isLogin()) {
throw new ZhydCommentException("站长已关闭匿名评论,请先登录!");
}
// 过滤文本内容,防止xss
this.filterContent(comment);
if (SessionUtil.isLogin()) {
// 已登录且非匿名,使用当前登录用户的信息评论
if (SessionUtil.isLogin() && !anonymous) {
this.setCurrentLoginUserInfo(comment);
} else {
this.setCurrentAnonymousUserInfo(comment);
}
List<String> avatars = configService.getRandomUserAvatar();
if (StringUtils.isEmpty(comment.getAvatar()) && !CollectionUtils.isEmpty(avatars)) {
Collections.shuffle(avatars);
int randomIndex = new Random().nextInt(avatars.size());
comment.setAvatar(avatars.get(randomIndex));
// 用户没有头像时, 使用随机默认的头像
if (StringUtils.isEmpty(comment.getAvatar())) {
List<String> avatars = configService.getRandomUserAvatar();
if (!CollectionUtils.isEmpty(avatars)) {
Collections.shuffle(avatars);
int randomIndex = new Random().nextInt(avatars.size());
comment.setAvatar(avatars.get(randomIndex));
}
}
if (StringUtils.isEmpty(comment.getStatus())) {
comment.setStatus(CommentStatusEnum.VERIFYING.toString());
}
// set当前评论者的设备信息
this.setCurrentDeviceInfo(comment);
// set当前评论者的位置信息
this.setCurrentLocation(comment);
// 保存
this.insert(comment);
// 发送邮件通知
this.sendEmail(comment);
return comment;
}
......@@ -192,7 +206,7 @@ public class BizCommentServiceImpl implements BizCommentService {
throw new ZhydCommentException("说点什么吧");
}
// 过滤非法属性和无用的空标签
if (!XssKillerUtil.isValid(content)) {
if (!XssKillerUtil.isValid(content) || !XssKillerUtil.isValid(comment.getAvatar())) {
throw new ZhydCommentException("请不要使用特殊标签");
}
content = XssKillerUtil.clean(content.trim()).replaceAll("(<p><br></p>)|(<p></p>)", "");
......
......@@ -141,12 +141,12 @@
<div class="menu-box">
<div class="navbar-header">
<span class="pull-right nav-search toggle-search" data-toggle="modal" data-target=".nav-search-box"><i class="fa fa-search"></i></span>
<a type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<button class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
</button>
<a class="navbar-brand logo" href="#"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册