mirror of https://github.com/halo-dev/halo
🐛 Fixing some bug.
parent
9d215f2fbc
commit
3ae12ba69f
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.admin;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
|
@ -110,11 +111,12 @@ public class CommentController extends BaseController{
|
|||
HttpSession session){
|
||||
Comment comment = commentService.updateCommentStatus(commentId,0);
|
||||
|
||||
//判断评论者的邮箱是否符合规则
|
||||
Pattern patternEmail = Pattern.compile("\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}");
|
||||
Matcher matcher = patternEmail.matcher(comment.getCommentAuthorEmail());
|
||||
|
||||
//判断是否启用邮件服务
|
||||
if("true".equals(HaloConst.OPTIONS.get("smtp_email_enable"))) {
|
||||
if("true".equals(HaloConst.OPTIONS.get("smtp_email_enable")) && "true".equals(HaloConst.OPTIONS.get("comment_pass_notice"))) {
|
||||
try {
|
||||
if (status == 1 && matcher.find()) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
@ -170,26 +172,53 @@ public class CommentController extends BaseController{
|
|||
@RequestParam("postId") Long postId,
|
||||
@RequestParam("commentContent") String commentContent,
|
||||
@RequestParam("userAgent") String userAgent,
|
||||
HttpServletRequest request){
|
||||
HttpServletRequest request,
|
||||
HttpSession session){
|
||||
try {
|
||||
Post post = new Post();
|
||||
post.setPostId(postId);
|
||||
|
||||
//博主信息
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
|
||||
//被回复的评论
|
||||
Comment lastComment = commentService.findCommentById(commentId).get();
|
||||
|
||||
//保存评论
|
||||
Comment comment = new Comment();
|
||||
comment.setPost(post);
|
||||
comment.setCommentAuthor(userService.findAllUser().get(0).getUserDisplayName());
|
||||
comment.setCommentAuthorEmail(userService.findAllUser().get(0).getUserEmail());
|
||||
comment.setCommentAuthor(user.getUserDisplayName());
|
||||
comment.setCommentAuthorEmail(user.getUserEmail());
|
||||
comment.setCommentAuthorUrl(HaloConst.OPTIONS.get("site_url"));
|
||||
comment.setCommentAuthorIp(HaloUtil.getIpAddr(request));
|
||||
comment.setCommentAuthorAvatarMd5(HaloUtil.getMD5(userService.findAllUser().get(0).getUserEmail()));
|
||||
comment.setCommentDate(new Date());
|
||||
String at = "<a href='#'>@"+commentService.findCommentById(commentId).get().getCommentAuthor()+"</a>";
|
||||
comment.setCommentContent(at+commentContent);
|
||||
String lastContent = " //<a href='#'>@"+lastComment.getCommentAuthor()+"</a>:"+lastComment.getCommentContent();
|
||||
comment.setCommentContent(commentContent+lastContent);
|
||||
comment.setCommentAgent(userAgent);
|
||||
comment.setCommentParent(commentId);
|
||||
comment.setCommentStatus(0);
|
||||
commentService.saveByComment(comment);
|
||||
|
||||
//正则表达式判断对方的邮箱是否是正确的格式
|
||||
Pattern patternEmail = Pattern.compile("\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}");
|
||||
Matcher matcher = patternEmail.matcher(lastComment.getCommentAuthorEmail());
|
||||
|
||||
//邮件通知
|
||||
if("true".equals(HaloConst.OPTIONS.get("smtp_email_enable")) && "true".equals(HaloConst.OPTIONS.get("comment_reply_notice"))) {
|
||||
if(matcher.find()){
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("siteTitle",HaloConst.OPTIONS.get("site_title"));
|
||||
map.put("commentAuthor",lastComment.getCommentAuthor());
|
||||
map.put("pageName",lastComment.getPost().getPostTitle());
|
||||
map.put("commentContent",lastComment.getCommentContent());
|
||||
map.put("replyAuthor",user.getUserDisplayName());
|
||||
map.put("replyContent",commentContent);
|
||||
map.put("siteUrl",HaloConst.OPTIONS.get("site_url"));
|
||||
mailService.sendTemplateMail(
|
||||
lastComment.getCommentAuthorEmail(),"您在"+HaloConst.OPTIONS.get("site_title")+"的评论有了新回复",map,"common/mail/mail_reply.ftl");
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("回复评论失败!"+e.getMessage());
|
||||
}
|
||||
|
|
|
@ -230,35 +230,35 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="newCommentNotice" class="col-sm-2 control-label">新评论通知:</label>
|
||||
<label class="col-sm-2 control-label">新评论通知:</label>
|
||||
<div class="col-sm-4">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="new_comment_notice" id="newCommentNotice" value="true" ${((options.new_comment_notice?if_exists)=='true')?string('checked','')}> 启用
|
||||
<input type="radio" name="new_comment_notice" value="true" ${((options.new_comment_notice?if_exists)=='true')?string('checked','')}> 启用
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="new_comment_notice" id="newCommentNotice" value="false" ${((options.new_comment_notice?if_exists)=='false')?string('checked','')}> 禁用
|
||||
<input type="radio" name="new_comment_notice" value="false" ${((options.new_comment_notice?if_exists)=='false')?string('checked','')}> 禁用
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="commentPassNotice" class="col-sm-2 control-label">评论审核通过通知对方:</label>
|
||||
<label class="col-sm-2 control-label">评论审核通过通知对方:</label>
|
||||
<div class="col-sm-4">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="comment_pass_notice" id="commentPassNotice" value="true" ${((options.comment_pass_notice?if_exists)=='true')?string('checked','')}> 启用
|
||||
<input type="radio" name="comment_pass_notice" value="true" ${((options.comment_pass_notice?if_exists)=='true')?string('checked','')}> 启用
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="comment_pass_notice" id="commentPassNotice" value="false" ${((options.comment_pass_notice?if_exists)=='false')?string('checked','')}> 禁用
|
||||
<input type="radio" name="comment_pass_notice" value="false" ${((options.comment_pass_notice?if_exists)=='false')?string('checked','')}> 禁用
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="commentReplyNotice" class="col-sm-2 control-label">评论回复通知对方:</label>
|
||||
<label class="col-sm-2 control-label">评论回复通知对方:</label>
|
||||
<div class="col-sm-4">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="comment_reply_notice" id="commentReplyNotice" value="true" ${((options.comment_reply_notice?if_exists)=='true')?string('checked','')}> 启用
|
||||
<input type="radio" name="comment_reply_notice" value="true" ${((options.comment_reply_notice?if_exists)=='true')?string('checked','')}> 启用
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="comment_reply_notice" id="commentReplyNotice" value="false" ${((options.comment_reply_notice?if_exists)=='false')?string('checked','')}> 禁用
|
||||
<input type="radio" name="comment_reply_notice" value="false" ${((options.comment_reply_notice?if_exists)=='false')?string('checked','')}> 禁用
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -379,24 +379,24 @@
|
|||
<form method="post" class="form-horizontal" id="adminOptions">
|
||||
<div class="box-body">
|
||||
<div class="form-group">
|
||||
<label for="adminPjax" class="col-sm-2 control-label">启用pjax:</label>
|
||||
<label class="col-sm-2 control-label">启用pjax:</label>
|
||||
<div class="col-sm-4">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="admin_pjax" id="adminPjax" value="true" ${((options.admin_pjax?default('true'))=='true')?string('checked','')}> 启用
|
||||
<input type="radio" name="admin_pjax" value="true" ${((options.admin_pjax?default('true'))=='true')?string('checked','')}> 启用
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="admin_pjax" id="adminPjax" value="false" ${((options.admin_pjax?if_exists)=='false')?string('checked','')}> 禁用
|
||||
<input type="radio" name="admin_pjax" value="false" ${((options.admin_pjax?if_exists)=='false')?string('checked','')}> 禁用
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="adminLayout" class="col-sm-2 control-label">后台布局:</label>
|
||||
<label class="col-sm-2 control-label">后台布局:</label>
|
||||
<div class="col-sm-4">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="admin_layout" id="adminLayout" value="" ${((options.admin_layout?default(''))=='')?string('checked','')}> 正常布局
|
||||
<input type="radio" name="admin_layout" value="" ${((options.admin_layout?default(''))=='')?string('checked','')}> 正常布局
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="admin_layout" id="adminLayout" value="layout-boxed" ${((options.admin_layout?default(''))=='layout-boxed')?string('checked','')}> 盒子布局
|
||||
<input type="radio" name="admin_layout" value="layout-boxed" ${((options.admin_layout?default(''))=='layout-boxed')?string('checked','')}> 盒子布局
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -420,13 +420,13 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="sidebarStyle" class="col-sm-2 control-label">侧边栏样式:</label>
|
||||
<label class="col-sm-2 control-label">侧边栏样式:</label>
|
||||
<div class="col-sm-4">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="sidebar_style" id="sidebarStyle" value="" ${((options.sidebar_style?default(''))=='')?string('checked','')}> 展开
|
||||
<input type="radio" name="sidebar_style" value="" ${((options.sidebar_style?default(''))=='')?string('checked','')}> 展开
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="sidebar_style" id="sidebarStyle" value="sidebar-collapse" ${((options.sidebar_style?default(''))=='sidebar-collapse')?string('checked','')}> 收拢
|
||||
<input type="radio" name="sidebar_style" value="sidebar-collapse" ${((options.sidebar_style?default(''))=='sidebar-collapse')?string('checked','')}> 收拢
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -468,18 +468,18 @@
|
|||
<form method="post" class="form-horizontal" id="emailOptions">
|
||||
<div class="box-body">
|
||||
<div class="form-group">
|
||||
<label for="smtpEmailEnable" class="col-sm-2 control-label">是否启用:</label>
|
||||
<label class="col-sm-2 control-label">是否启用:</label>
|
||||
<div class="col-sm-4">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="smtp_email_enable" id="smtpEmailEnable" value="true" ${((options.smtp_email_enable?default('false'))=='true')?string('checked','')}> 启用
|
||||
<input type="radio" name="smtp_email_enable" value="true" ${((options.smtp_email_enable?default('false'))=='true')?string('checked','')}> 启用
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="smtp_email_enable" id="smtpEmailEnable" value="false" ${((options.smtp_email_enable?if_exists)=='false')?string('checked','')}> 禁用
|
||||
<input type="radio" name="smtp_email_enable" value="false" ${((options.smtp_email_enable?if_exists)=='false')?string('checked','')}> 禁用
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="emailSmtpHost" class="col-sm-2 control-label">SMTP地址:</label>
|
||||
<label for="emSmtpHost" class="col-sm-2 control-label">SMTP地址:</label>
|
||||
<div class="col-sm-4">
|
||||
<input type="text" class="form-control" id="emailSmtpHost" name="mail_smtp_host" value="${options.mail_smtp_host?if_exists}">
|
||||
</div>
|
||||
|
|
|
@ -2,28 +2,28 @@
|
|||
<div class="emailcontent" style="width:100%;max-width:720px;text-align: left;margin: 0 auto;padding-top: 20px;padding-bottom: 80px">
|
||||
<div class="emailtitle" style="border-radius: 5px;border:1px solid #eee;overflow: hidden;">
|
||||
<h1 style="color:#fff;background: #3798e8;line-height:70px;font-size:24px;font-weight:normal;padding-left:40px;margin:0">
|
||||
您在太傅上的留言有回复啦!
|
||||
您在${siteTitle}上的留言有回复啦!
|
||||
</h1>
|
||||
<div class="emailtext" style="background:#fff;padding:20px 32px 40px;">
|
||||
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">RYAN0UP, 您好!</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">您在《关于》的留言:
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">${commentAuthor}, 您好!</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">您在《${pageName}》的留言:
|
||||
<br />
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0px">文章质量越来越高了,加油!</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">TaiFu_S 给你的回复:
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0px">${commentContent}</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">${replyAuthor} 给你的回复:
|
||||
<br />
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0px">哈哈,谢谢!共同进步!</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0px">${replyContent}</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">你可以点击
|
||||
<a href="https://taifua.com/about/comment-page-4#comment-225">查看完整内容</a>
|
||||
<a href="${siteUrl}">查看完整内容</a>
|
||||
</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">欢迎再度光临
|
||||
<a href="https://taifua.com">太傅</a>
|
||||
<a href="${siteUrl}">${siteTitle}</a>
|
||||
</p>
|
||||
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">(此邮件由系统自动发出, 请勿回复。)</p>
|
||||
</div>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;text-align:right;padding:0 32px">邮件发自:
|
||||
<a href="https://taifua.com" style="color:#51a0e3;text-decoration:none">太傅</a>
|
||||
<a href="${siteUrl}" style="color:#51a0e3;text-decoration:none">${siteTitle}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue