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

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

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