mirror of https://github.com/halo-dev/halo
Send email to admin when have a new comment.
parent
bfc19c9cf3
commit
6b663cce6a
|
@ -1,14 +1,21 @@
|
||||||
package run.halo.app.event.comment;
|
package run.halo.app.event.comment;
|
||||||
|
|
||||||
|
import cn.hutool.core.text.StrBuilder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import run.halo.app.exception.ServiceException;
|
||||||
import run.halo.app.model.entity.Comment;
|
import run.halo.app.model.entity.Comment;
|
||||||
|
import run.halo.app.model.entity.Post;
|
||||||
|
import run.halo.app.model.entity.User;
|
||||||
|
import run.halo.app.model.properties.BlogProperties;
|
||||||
import run.halo.app.model.properties.CommentProperties;
|
import run.halo.app.model.properties.CommentProperties;
|
||||||
import run.halo.app.service.CommentService;
|
import run.halo.app.service.*;
|
||||||
import run.halo.app.service.MailService;
|
|
||||||
import run.halo.app.service.OptionService;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment event listener.
|
* Comment event listener.
|
||||||
|
@ -26,12 +33,20 @@ public class CommentEventListener {
|
||||||
|
|
||||||
private final CommentService commentService;
|
private final CommentService commentService;
|
||||||
|
|
||||||
|
private final PostService postService;
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
public CommentEventListener(MailService mailService,
|
public CommentEventListener(MailService mailService,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
CommentService commentService) {
|
CommentService commentService,
|
||||||
|
PostService postService,
|
||||||
|
UserService userService) {
|
||||||
this.mailService = mailService;
|
this.mailService = mailService;
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
this.commentService = commentService;
|
this.commentService = commentService;
|
||||||
|
this.postService = postService;
|
||||||
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
|
@ -44,10 +59,23 @@ public class CommentEventListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User user = userService.getCurrentUser().orElseThrow(() -> new ServiceException("Can not find blog owner"));
|
||||||
|
|
||||||
// Get comment id
|
// Get comment id
|
||||||
Comment comment = commentService.getById(newEvent.getCommentId());
|
Comment comment = commentService.getById(newEvent.getCommentId());
|
||||||
|
|
||||||
// TODO Complete mail sending
|
Post post = postService.getById(comment.getPostId());
|
||||||
|
|
||||||
|
Map<String, Object> data = new HashMap<>();
|
||||||
|
|
||||||
|
StrBuilder url = new StrBuilder(optionService.getByPropertyOfNullable(BlogProperties.BLOG_URL))
|
||||||
|
.append("/archives/")
|
||||||
|
.append(post.getUrl());
|
||||||
|
data.put("url", url.toString());
|
||||||
|
data.put("page", post.getTitle());
|
||||||
|
data.put("author", comment.getAuthor());
|
||||||
|
data.put("content",comment.getContent());
|
||||||
|
mailService.sendTemplateMail(user.getEmail(), "您的博客有新的评论", data, "common/mail_template/mail_notice.ftl");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package run.halo.app.web.controller.admin;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Admin page.
|
||||||
|
*
|
||||||
|
* @author : RYAN0UP
|
||||||
|
* @date : 2019-04-23
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
public class MainController {
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/admin")
|
||||||
|
public String admin() {
|
||||||
|
return "redirect:/admin/index.html";
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping(value = "archives")
|
@RequestMapping(value = "/archives")
|
||||||
public class ContentArchiveController {
|
public class ContentArchiveController {
|
||||||
|
|
||||||
private final PostService postService;
|
private final PostService postService;
|
||||||
|
|
|
@ -83,9 +83,4 @@ public class ContentIndexController {
|
||||||
model.addAttribute("rainbow", rainbow);
|
model.addAttribute("rainbow", rainbow);
|
||||||
return themeService.render("index");
|
return themeService.render("index");
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/admin")
|
|
||||||
public String admin() {
|
|
||||||
return "redirect:/admin/index.html";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,14 @@
|
||||||
您的博客有新的评论!
|
您的博客有新的评论!
|
||||||
</h1>
|
</h1>
|
||||||
<div class="emailtext" style="background:#fff;padding:20px 32px 40px;">
|
<div class="emailtext" style="background:#fff;padding:20px 32px 40px;">
|
||||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">${author}, 您好!</p>
|
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">${user.nickName!}, 您好!</p>
|
||||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">有访客在《${pageName}》留言:</p>
|
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">有访客在《${page!}》留言:</p>
|
||||||
<br />
|
<br />
|
||||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0px">
|
<p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0">
|
||||||
${visitor}:${commentContent}
|
${content!}:${commentContent!}
|
||||||
</p>
|
</p>
|
||||||
<br />
|
<br />
|
||||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">你可以点击<a href="${pageUrl}">查看完整内容</a></p>
|
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">你可以点击<a href="${url!}">查看完整内容</a></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
Loading…
Reference in New Issue