diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/CommentController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/CommentController.java index 886fdb6d8..b7cdc098d 100755 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/CommentController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/CommentController.java @@ -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 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 = "@"+commentService.findCommentById(commentId).get().getCommentAuthor()+""; - comment.setCommentContent(at+commentContent); + String lastContent = " //@"+lastComment.getCommentAuthor()+":"+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 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()); } diff --git a/src/main/resources/templates/admin/admin_option.ftl b/src/main/resources/templates/admin/admin_option.ftl index c0af7c4f5..f1b082729 100755 --- a/src/main/resources/templates/admin/admin_option.ftl +++ b/src/main/resources/templates/admin/admin_option.ftl @@ -230,35 +230,35 @@
- +
- +
- +
@@ -379,24 +379,24 @@
- +
- +
@@ -420,13 +420,13 @@
- +
@@ -468,18 +468,18 @@
- +
- +
diff --git a/src/main/resources/templates/common/mail/mail_reply.ftl b/src/main/resources/templates/common/mail/mail_reply.ftl index 02405ef17..c579018c2 100644 --- a/src/main/resources/templates/common/mail/mail_reply.ftl +++ b/src/main/resources/templates/common/mail/mail_reply.ftl @@ -2,28 +2,28 @@

- 您在太傅上的留言有回复啦! + 您在${siteTitle}上的留言有回复啦!

-

RYAN0UP, 您好!

-

您在《关于》的留言: +

${commentAuthor}, 您好!

+

您在《${pageName}》的留言:
-

文章质量越来越高了,加油!

-

TaiFu_S 给你的回复: +

${commentContent}

+

${replyAuthor} 给你的回复:
-

哈哈,谢谢!共同进步!

+

${replyContent}

你可以点击 - 查看完整内容 + 查看完整内容

欢迎再度光临 - 太傅 + ${siteTitle}

(此邮件由系统自动发出, 请勿回复。)

邮件发自: - 太傅 + ${siteTitle}