pull/157/head
johnniang 2019-05-13 00:47:07 +08:00
parent 9642dd994a
commit 7b480ca32e
4 changed files with 24 additions and 4 deletions

View File

@ -16,6 +16,7 @@ import org.springframework.util.CollectionUtils;
import run.halo.app.event.comment.CommentNewEvent;
import run.halo.app.event.comment.CommentPassEvent;
import run.halo.app.event.comment.CommentReplyEvent;
import run.halo.app.exception.BadRequestException;
import run.halo.app.model.dto.BaseCommentDTO;
import run.halo.app.model.entity.BaseComment;
import run.halo.app.model.entity.User;
@ -32,6 +33,7 @@ import run.halo.app.repository.base.BaseCommentRepository;
import run.halo.app.security.authentication.Authentication;
import run.halo.app.security.context.SecurityContextHolder;
import run.halo.app.service.OptionService;
import run.halo.app.service.UserService;
import run.halo.app.service.base.AbstractCrudService;
import run.halo.app.service.base.BaseCommentService;
import run.halo.app.utils.ServiceUtils;
@ -55,14 +57,17 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
protected final OptionService optionService;
protected final UserService userService;
protected final ApplicationEventPublisher eventPublisher;
public BaseCommentServiceImpl(BaseCommentRepository<COMMENT> baseCommentRepository,
OptionService optionService,
ApplicationEventPublisher eventPublisher) {
UserService userService, ApplicationEventPublisher eventPublisher) {
super(baseCommentRepository);
this.baseCommentRepository = baseCommentRepository;
this.optionService = optionService;
this.userService = userService;
this.eventPublisher = eventPublisher;
}
@ -275,6 +280,7 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
// Blogger comment
User user = authentication.getDetail().getUser();
commentParam.setAuthor(StringUtils.isBlank(user.getNickname()) ? user.getUsername() : user.getNickname());
commentParam.setEmail(user.getEmail());
@ -284,6 +290,14 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
// Validate the comment param manually
ValidationUtils.validate(commentParam);
if (authentication == null) {
// Anonymous comment
// Check email
if (userService.getByEmail(commentParam.getEmail()).isPresent()) {
throw new BadRequestException("不能使用博主的邮件,如果您是博主,请登录管理端进行回复。");
}
}
// Convert to comment
return create(commentParam.convertTo());
}

View File

@ -15,6 +15,7 @@ import run.halo.app.repository.JournalCommentRepository;
import run.halo.app.repository.JournalRepository;
import run.halo.app.service.JournalCommentService;
import run.halo.app.service.OptionService;
import run.halo.app.service.UserService;
import run.halo.app.utils.ServiceUtils;
import java.util.Collections;
@ -38,8 +39,9 @@ public class JournalCommentServiceImpl extends BaseCommentServiceImpl<JournalCom
public JournalCommentServiceImpl(JournalCommentRepository journalCommentRepository,
OptionService optionService,
UserService userService,
ApplicationEventPublisher eventPublisher, JournalRepository journalRepository) {
super(journalCommentRepository, optionService, eventPublisher);
super(journalCommentRepository, optionService, userService, eventPublisher);
this.journalCommentRepository = journalCommentRepository;
this.journalRepository = journalRepository;
}

View File

@ -18,6 +18,7 @@ import run.halo.app.repository.PostCommentRepository;
import run.halo.app.repository.PostRepository;
import run.halo.app.service.OptionService;
import run.halo.app.service.PostCommentService;
import run.halo.app.service.UserService;
import run.halo.app.utils.ServiceUtils;
import java.util.Collections;
@ -42,9 +43,10 @@ public class PostCommentServiceImpl extends BaseCommentServiceImpl<PostComment>
public PostCommentServiceImpl(PostCommentRepository postCommentRepository,
PostRepository postRepository,
UserService userService,
OptionService optionService,
ApplicationEventPublisher eventPublisher) {
super(postCommentRepository, optionService, eventPublisher);
super(postCommentRepository, optionService, userService, eventPublisher);
this.postCommentRepository = postCommentRepository;
this.postRepository = postRepository;
}

View File

@ -15,6 +15,7 @@ import run.halo.app.repository.SheetCommentRepository;
import run.halo.app.repository.SheetRepository;
import run.halo.app.service.OptionService;
import run.halo.app.service.SheetCommentService;
import run.halo.app.service.UserService;
import run.halo.app.utils.ServiceUtils;
import java.util.Collections;
@ -38,9 +39,10 @@ public class SheetCommentServiceImpl extends BaseCommentServiceImpl<SheetComment
public SheetCommentServiceImpl(SheetCommentRepository sheetCommentRepository,
OptionService optionService,
UserService userService,
ApplicationEventPublisher eventPublisher,
SheetRepository sheetRepository) {
super(sheetCommentRepository, optionService, eventPublisher);
super(sheetCommentRepository, optionService, userService, eventPublisher);
this.sheetCommentRepository = sheetCommentRepository;
this.sheetRepository = sheetRepository;
}