From a220cc007877e8ad9beb3e14c7a58c61a3bfa637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Fri, 5 Jul 2019 09:11:42 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E6=A0=87=E9=A2=98=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=E9=99=90=E5=88=B6=E6=94=B9=E6=88=90150=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fstack/constant/PostConstant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/fstack/constant/PostConstant.java b/src/main/java/com/fstack/constant/PostConstant.java index fa5c481..feee95b 100644 --- a/src/main/java/com/fstack/constant/PostConstant.java +++ b/src/main/java/com/fstack/constant/PostConstant.java @@ -6,7 +6,7 @@ package com.fstack.constant; */ public class PostConstant { - public static final int TITLE_LENGTH_MAX = 30; + public static final int TITLE_LENGTH_MAX = 150; public static final int TITLE_LENGTH_MIN = 3; public static final int BODY_LENGTH_MAX = 65535; -- Gitee From dcc796e6eb6ed2c2a25c3470e665cb2c4c8bbd3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Fri, 5 Jul 2019 10:45:20 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E5=99=A8=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fstack/config/GlobalExceptionHandler.java | 14 +- .../com/fstack/constant/CommentConstant.java | 11 + .../validator/NewCommentFormValidator.java | 33 ++- .../fstack/web/controller/PostController.java | 206 +++++++++--------- src/main/resources/messages.properties | 6 +- 5 files changed, 157 insertions(+), 113 deletions(-) create mode 100644 src/main/java/com/fstack/constant/CommentConstant.java diff --git a/src/main/java/com/fstack/config/GlobalExceptionHandler.java b/src/main/java/com/fstack/config/GlobalExceptionHandler.java index 7d0850e..27ab971 100644 --- a/src/main/java/com/fstack/config/GlobalExceptionHandler.java +++ b/src/main/java/com/fstack/config/GlobalExceptionHandler.java @@ -5,26 +5,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Enumeration; -/** - * @author Hu Jie - * @date 2019/04/23 10:21 AM - */ -@ControllerAdvice +@RestControllerAdvice public class GlobalExceptionHandler { private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); - /** - * 捕获具体指定外的所有异常 - * - * @param ex - * @param request - * @param response - */ @ExceptionHandler(value = Exception.class) public ApiResponse handle(Exception ex, HttpServletRequest request, HttpServletResponse response) { logger.error("***** GlobalException Start *****"); diff --git a/src/main/java/com/fstack/constant/CommentConstant.java b/src/main/java/com/fstack/constant/CommentConstant.java new file mode 100644 index 0000000..fcefe6d --- /dev/null +++ b/src/main/java/com/fstack/constant/CommentConstant.java @@ -0,0 +1,11 @@ +package com.fstack.constant; + +public class CommentConstant { + + + public static final int COMMENT_LENGTH_MAX = 1024; + public static final int COMMENT_LENGTH_MIN = 1; + + private CommentConstant() { + } +} diff --git a/src/main/java/com/fstack/validator/NewCommentFormValidator.java b/src/main/java/com/fstack/validator/NewCommentFormValidator.java index d1f79b2..3d87e1a 100644 --- a/src/main/java/com/fstack/validator/NewCommentFormValidator.java +++ b/src/main/java/com/fstack/validator/NewCommentFormValidator.java @@ -1,5 +1,36 @@ package com.fstack.validator; -public class NewCommentFormValidator { +import com.fstack.constant.CommentConstant; +import com.fstack.persistence.model.Comment; +import com.fstack.persistence.model.Post; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.MessageSource; +import org.springframework.stereotype.Component; +import org.springframework.validation.Errors; +import org.springframework.validation.ValidationUtils; +import org.springframework.validation.Validator; + +@Component +public class NewCommentFormValidator implements Validator { + + @Autowired + private MessageSource messageSource; + + @Override + public boolean supports(Class clazz) { + return Post.class.equals(clazz); + } + + @Override + public void validate(Object object, Errors errors) { + Comment newComment = (Comment) object; + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "comment", "NotEmpty"); + if (newComment.getBody() != null && !newComment.getBody().isEmpty()) { + if (newComment.getBody().length() < CommentConstant.COMMENT_LENGTH_MIN || newComment.getBody().length() > CommentConstant.COMMENT_LENGTH_MAX) { + errors.rejectValue("comment", "comment.length", messageSource.getMessage("comment.length", null, null)); + } + } + + } } diff --git a/src/main/java/com/fstack/web/controller/PostController.java b/src/main/java/com/fstack/web/controller/PostController.java index 63d71e5..c6eb891 100644 --- a/src/main/java/com/fstack/web/controller/PostController.java +++ b/src/main/java/com/fstack/web/controller/PostController.java @@ -4,6 +4,7 @@ import java.util.Map; import javax.validation.Valid; +import com.fstack.validator.NewCommentFormValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -30,103 +31,112 @@ import com.fstack.web.dto.PostDto; @Controller public class PostController { - private static final Logger logger = LoggerFactory.getLogger(PostController.class); - - @Autowired - private PostService postService; - - @Autowired - private CategoryService categoryService; - - @Autowired - private CommentService commentService; - - @Autowired - private NewPostFormValidator newPostValidator; - - @Autowired - ApplicationEventPublisher eventPublisher; - - @RequestMapping(value = "/post/list", method = RequestMethod.GET) - public String index(Model model) { - Map attributes = postService.findPosts(); - if (null == attributes) { - throw new ResourceNotFoundException("attributes not found."); - } - model.addAttribute(attributes); - return "fragments/posts-list"; - } - - @RequestMapping(value = "/post/{postId}", method = RequestMethod.GET) - public String getPost(Model model, @PathVariable Long postId) { - if (null == postId) { - throw new BadRequestException("Path variable postId cound not be null."); - } - Map attributes = this.postService.findPostDetailsAndCommentsByPostId(postId); - if (null == attributes) { - throw new ResourceNotFoundException("attributes not found."); - } - model.addAllAttributes(attributes); - return "forum/post"; - } - - @RequestMapping(value = "/new/{categoryName}", method = RequestMethod.GET) - public String displayNewPostPageWithCategory(Model model, @PathVariable String categoryName) { - if (null == categoryName) { - throw new BadRequestException("Path variable postId cound not be null."); - } - Map attributes = this.categoryService.getNewPostPageWithCategoryName(categoryName); - if (null == attributes) { - throw new ResourceNotFoundException("attributes not found."); - } - model.addAllAttributes(attributes); - return "forum/new-post"; - } - - @RequestMapping(value = "/new", method = RequestMethod.GET) - public String displayNewPostPage(Model model) { - Map attributes = this.categoryService.getNewPostPageWithCategorySelect(); - if (null == attributes) { - throw new ResourceNotFoundException("attributes not found."); - } - model.addAllAttributes(attributes); - return "forum/new-post"; - } - - @RequestMapping(value = "/new", method = RequestMethod.POST) - public String processNewPost(@Valid @ModelAttribute("postDto") PostDto postDto, BindingResult bindingResult, - Model model) { - if (null == postDto) { - throw new BadRequestException("NewPostForm cound not be null."); - } - Post post = this.postService.createNewPost(postDto); - if (null == post) { - throw new ResourceNotFoundException("New post object can't be created."); - } - // post form validation - this.newPostValidator.validate(post, bindingResult); - if (bindingResult.hasErrors()) { - logger.info("BindingResult has errors >> " + bindingResult.getFieldError()); - return "forum/new-post"; - } else { - this.postService.save(post); - } - return "redirect:/"; - } - - @RequestMapping(value = "/post/{postId}", method = RequestMethod.POST) - public String processNewComment(@PathVariable Long postId, - @Valid @ModelAttribute("commentDto") CommentDto commentDto) { - if (null == postId && null == commentDto) { - throw new BadRequestException("Path variable postId and newCommentForm cound not be null."); - } - Comment comment = this.commentService.createNewCommentOnPost(postId, commentDto); - if (null == comment) { - throw new ResourceNotFoundException("New comment object can't be created."); - } - // comment form validation here ... - this.commentService.save(comment); - return "redirect:/post/{postId}"; - } + private static final Logger logger = LoggerFactory.getLogger(PostController.class); + + @Autowired + private PostService postService; + + @Autowired + private CategoryService categoryService; + + @Autowired + private CommentService commentService; + + @Autowired + private NewPostFormValidator newPostValidator; + + @Autowired + private NewCommentFormValidator newCommentFormValidator; + + @Autowired + ApplicationEventPublisher eventPublisher; + + @RequestMapping(value = "/post/list", method = RequestMethod.GET) + public String index(Model model) { + Map attributes = postService.findPosts(); + if (null == attributes) { + throw new ResourceNotFoundException("attributes not found."); + } + model.addAttribute(attributes); + return "fragments/posts-list"; + } + + @RequestMapping(value = "/post/{postId}", method = RequestMethod.GET) + public String getPost(Model model, @PathVariable Long postId) { + if (null == postId) { + throw new BadRequestException("Path variable postId cound not be null."); + } + Map attributes = this.postService.findPostDetailsAndCommentsByPostId(postId); + if (null == attributes) { + throw new ResourceNotFoundException("attributes not found."); + } + model.addAllAttributes(attributes); + return "forum/post"; + } + + @RequestMapping(value = "/new/{categoryName}", method = RequestMethod.GET) + public String displayNewPostPageWithCategory(Model model, @PathVariable String categoryName) { + if (null == categoryName) { + throw new BadRequestException("Path variable postId cound not be null."); + } + Map attributes = this.categoryService.getNewPostPageWithCategoryName(categoryName); + if (null == attributes) { + throw new ResourceNotFoundException("attributes not found."); + } + model.addAllAttributes(attributes); + return "forum/new-post"; + } + + @RequestMapping(value = "/new", method = RequestMethod.GET) + public String displayNewPostPage(Model model) { + Map attributes = this.categoryService.getNewPostPageWithCategorySelect(); + if (null == attributes) { + throw new ResourceNotFoundException("attributes not found."); + } + model.addAllAttributes(attributes); + return "forum/new-post"; + } + + @RequestMapping(value = "/new", method = RequestMethod.POST) + public String processNewPost(@Valid @ModelAttribute("postDto") PostDto postDto, BindingResult bindingResult, + Model model) { + if (null == postDto) { + throw new BadRequestException("NewPostForm cound not be null."); + } + Post post = this.postService.createNewPost(postDto); + if (null == post) { + throw new ResourceNotFoundException("New post object can't be created."); + } + // post form validation + this.newPostValidator.validate(post, bindingResult); + if (bindingResult.hasErrors()) { + logger.info("BindingResult has errors >> " + bindingResult.getFieldError()); + return "forum/new-post"; + } else { + this.postService.save(post); + } + return "redirect:/"; + } + + @RequestMapping(value = "/post/{postId}", method = RequestMethod.POST) + public String processNewComment(@PathVariable Long postId, + @Valid @ModelAttribute("commentDto") CommentDto commentDto, BindingResult bindingResult) { + if (null == postId && null == commentDto) { + throw new BadRequestException("Path variable postId and newCommentForm cound not be null."); + } + Comment comment = this.commentService.createNewCommentOnPost(postId, commentDto); + if (null == comment) { + throw new ResourceNotFoundException("New comment object can't be created."); + } + // comment form validation + this.newCommentFormValidator.validate(comment, bindingResult); + if (bindingResult.hasErrors()) { + logger.info("BindingResult has errors >> " + bindingResult.getFieldError()); + throw new BadRequestException(bindingResult.getFieldError().getDefaultMessage()); + } else { + this.commentService.save(comment); + } + return "redirect:/post/{postId}"; + } } \ No newline at end of file diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index f56f6c8..d1f7b6a 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -7,5 +7,7 @@ userForm.email.duplicate=This Email already exists. userForm.password.length=Try one with at least 5 characters. userForm.password.diff=These passwords don't match. # new post messages -post.title.length=Title of new post must use 3 and 30 characters. -post.body.length=Title of new post must use 3 and 30 characters. +post.title.length=Title of new post must use 3 and 150 characters. +post.body.length=Body of new post must use 3 and 65535 characters. +# new comment messages +comment.length=Comment of new post must use 1 to 1024 characters. -- Gitee From ac34a7e01be3606047e3062d3c4d3fe9afdf1d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Fri, 5 Jul 2019 10:45:42 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E5=99=A8=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fstack/config/GlobalExceptionHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/fstack/config/GlobalExceptionHandler.java b/src/main/java/com/fstack/config/GlobalExceptionHandler.java index 27ab971..7806a28 100644 --- a/src/main/java/com/fstack/config/GlobalExceptionHandler.java +++ b/src/main/java/com/fstack/config/GlobalExceptionHandler.java @@ -3,7 +3,6 @@ package com.fstack.config; import com.fstack.common.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -- Gitee From 41f71828b3bf07659c86ad04d0f0433374962cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Fri, 5 Jul 2019 11:03:58 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E5=99=A8=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fstack/validator/NewCommentFormValidator.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/fstack/validator/NewCommentFormValidator.java b/src/main/java/com/fstack/validator/NewCommentFormValidator.java index 3d87e1a..28353cf 100644 --- a/src/main/java/com/fstack/validator/NewCommentFormValidator.java +++ b/src/main/java/com/fstack/validator/NewCommentFormValidator.java @@ -2,7 +2,6 @@ package com.fstack.validator; import com.fstack.constant.CommentConstant; import com.fstack.persistence.model.Comment; -import com.fstack.persistence.model.Post; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.stereotype.Component; @@ -19,7 +18,7 @@ public class NewCommentFormValidator implements Validator { @Override public boolean supports(Class clazz) { - return Post.class.equals(clazz); + return Comment.class.equals(clazz); } @Override -- Gitee From 948e1974bb10838baf8307df21f22a95e08648aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Fri, 5 Jul 2019 11:28:22 +0800 Subject: [PATCH 05/12] =?UTF-8?q?pro=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-pro.properties | 53 +++++++++++++++++++ src/main/resources/application.properties | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/application-pro.properties diff --git a/src/main/resources/application-pro.properties b/src/main/resources/application-pro.properties new file mode 100644 index 0000000..cf0bb0b --- /dev/null +++ b/src/main/resources/application-pro.properties @@ -0,0 +1,53 @@ +# ============================== +# MySQL connection config +# ============================== +spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver +spring.datasource.url = jdbc:mysql://127.0.0.1:3306/fangrong?serverTimezone=GMT&useSSL=false&useUnicode=true&characterEncoding=UTF-8 +spring.datasource.username = fangrong +spring.datasource.password = GsWJAHJtNc2R85xx +spring.datasource.type=com.zaxxer.hikari.HikariDataSource +spring.datasource.hikari.minimum-idle=5 +spring.datasource.hikari.maximum-pool-size=15 +spring.datasource.hikari.auto-commit=true +spring.datasource.hikari.idle-timeout=60000 +spring.datasource.hikari.pool-name=fang +spring.datasource.hikari.max-lifetime=1800000 +spring.datasource.hikari.connection-timeout=30000 +spring.datasource.hikari.connection-test-query=SELECT 1 + +# ============================== +# Redis configuration +# ============================== +spring.redis.database=0 +spring.redis.host=192.168.1.130 +spring.redis.port=6379 +spring.redis.password=kaixin +spring.redis.timeout=5000ms +spring.redis.lettuce.pool.max-idle=10 +spring.redis.lettuce.pool.min-idle=5 +spring.redis.lettuce.pool.max-active=20 +spring.redis.lettuce.pool.max-wait=-1ms + +# ============================== +# SMTP Email +# ============================== +spring.mail.default-encoding=UTF-8 +spring.mail.host = smtp.163.com +spring.mail.username = look7788ab@163.com +spring.mail.password = look7788ab +spring.mail.properties.mail.smtp.auth=true +spring.mail.properties.mail.smtp.starttls.enable=true +spring.mail.properties.mail.smtp.starttls.required=true + +# ============================== +# service base URL for confirmation link +# ============================== +service.url=http://192.168.1.130:9999 + +# ============================== +# File upload configuration +# ============================== +spring.servlet.multipart.max-file-size=500KB +spring.servlet.multipart.max-request-size =500KB + +enable.swagger=true \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ee0979b..2c807f0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ server.port=9999 -spring.profiles.active= local +spring.profiles.active= pro server.servlet.context-path= / spring.aop.proxy-target-class=true # ============================== -- Gitee From 5555f4cf7a4998759e99f031c93ad2b04a31cc9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Fri, 5 Jul 2019 12:23:22 +0800 Subject: [PATCH 06/12] local --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2c807f0..ee0979b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ server.port=9999 -spring.profiles.active= pro +spring.profiles.active= local server.servlet.context-path= / spring.aop.proxy-target-class=true # ============================== -- Gitee From 73caf4559849243d923ee2f558281a62d46b08b2 Mon Sep 17 00:00:00 2001 From: ab <672943942@qq.com> Date: Fri, 5 Jul 2019 19:21:30 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.properties | 14 +++++++++----- src/main/resources/application-local.properties | 14 +++++++++----- src/main/resources/application-pro.properties | 14 +++++++++----- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index cf0bb0b..4275b23 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -31,13 +31,17 @@ spring.redis.lettuce.pool.max-wait=-1ms # ============================== # SMTP Email # ============================== -spring.mail.default-encoding=UTF-8 -spring.mail.host = smtp.163.com +spring.mail.default-encoding= UTF-8 +spring.mail.host= smtp.163.com +spring.mail.port= 465 +spring.mail.properties.mail.smtp.socketFactory.port = 465 +spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory +spring.mail.properties.mail.smtp.socketFactory.fallback = false spring.mail.username = look7788ab@163.com spring.mail.password = look7788ab -spring.mail.properties.mail.smtp.auth=true -spring.mail.properties.mail.smtp.starttls.enable=true -spring.mail.properties.mail.smtp.starttls.required=true +spring.mail.properties.mail.smtp.auth= true +spring.mail.properties.mail.smtp.starttls.enable= true +spring.mail.properties.mail.smtp.starttls.required= true # ============================== # service base URL for confirmation link diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index 7c9960f..3e3a6d6 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -31,13 +31,17 @@ spring.redis.lettuce.pool.max-wait=-1ms # ============================== # SMTP Email # ============================== -spring.mail.default-encoding=UTF-8 -spring.mail.host = smtp.163.com +spring.mail.default-encoding= UTF-8 +spring.mail.host= smtp.163.com +spring.mail.port= 465 +spring.mail.properties.mail.smtp.socketFactory.port = 465 +spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory +spring.mail.properties.mail.smtp.socketFactory.fallback = false spring.mail.username = look7788ab@163.com spring.mail.password = look7788ab -spring.mail.properties.mail.smtp.auth=true -spring.mail.properties.mail.smtp.starttls.enable=true -spring.mail.properties.mail.smtp.starttls.required=true +spring.mail.properties.mail.smtp.auth= true +spring.mail.properties.mail.smtp.starttls.enable= true +spring.mail.properties.mail.smtp.starttls.required= true # ============================== # service base URL for confirmation link diff --git a/src/main/resources/application-pro.properties b/src/main/resources/application-pro.properties index cf0bb0b..4275b23 100644 --- a/src/main/resources/application-pro.properties +++ b/src/main/resources/application-pro.properties @@ -31,13 +31,17 @@ spring.redis.lettuce.pool.max-wait=-1ms # ============================== # SMTP Email # ============================== -spring.mail.default-encoding=UTF-8 -spring.mail.host = smtp.163.com +spring.mail.default-encoding= UTF-8 +spring.mail.host= smtp.163.com +spring.mail.port= 465 +spring.mail.properties.mail.smtp.socketFactory.port = 465 +spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory +spring.mail.properties.mail.smtp.socketFactory.fallback = false spring.mail.username = look7788ab@163.com spring.mail.password = look7788ab -spring.mail.properties.mail.smtp.auth=true -spring.mail.properties.mail.smtp.starttls.enable=true -spring.mail.properties.mail.smtp.starttls.required=true +spring.mail.properties.mail.smtp.auth= true +spring.mail.properties.mail.smtp.starttls.enable= true +spring.mail.properties.mail.smtp.starttls.required= true # ============================== # service base URL for confirmation link -- Gitee From c4e149dd5cb06131dca7da9a29eb7bc69ce3f1c5 Mon Sep 17 00:00:00 2001 From: ab <672943942@qq.com> Date: Fri, 5 Jul 2019 19:25:44 +0800 Subject: [PATCH 08/12] bug fixed --- src/main/java/com/fstack/service/impl/CategoryServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/fstack/service/impl/CategoryServiceImpl.java b/src/main/java/com/fstack/service/impl/CategoryServiceImpl.java index 679cd71..28fa66f 100644 --- a/src/main/java/com/fstack/service/impl/CategoryServiceImpl.java +++ b/src/main/java/com/fstack/service/impl/CategoryServiceImpl.java @@ -26,7 +26,7 @@ public class CategoryServiceImpl implements CategoryService { public Map getNewPostPageWithCategoryName(String categoryName) { Map attributes = new HashMap<>(); Category category = this.categoryMapper.findByName(categoryName); - attributes.put("title", i18nUtil.getMessage("")); + attributes.put("title", i18nUtil.getMessage("post.new")); PostDto newPostForm = new PostDto(); newPostForm.setCategory(category.getName()); attributes.put("postDto", newPostForm); -- Gitee From 068e0b46c48f65711348a4e76eb3128a225fb272 Mon Sep 17 00:00:00 2001 From: ab <672943942@qq.com> Date: Fri, 5 Jul 2019 19:36:20 +0800 Subject: [PATCH 09/12] bug fixed --- src/main/resources/application-pro.properties | 12 ++++++------ src/main/resources/application.properties | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/resources/application-pro.properties b/src/main/resources/application-pro.properties index 4275b23..664f81d 100644 --- a/src/main/resources/application-pro.properties +++ b/src/main/resources/application-pro.properties @@ -2,9 +2,9 @@ # MySQL connection config # ============================== spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver -spring.datasource.url = jdbc:mysql://127.0.0.1:3306/fangrong?serverTimezone=GMT&useSSL=false&useUnicode=true&characterEncoding=UTF-8 -spring.datasource.username = fangrong -spring.datasource.password = GsWJAHJtNc2R85xx +spring.datasource.url = jdbc:mysql://127.0.0.1:3306/fs_forum?zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=GMT&useSSL=false&useUnicode=true&characterEncoding=UTF-8 +spring.datasource.username = fstack +spring.datasource.password = fstack spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.maximum-pool-size=15 @@ -21,7 +21,7 @@ spring.datasource.hikari.connection-test-query=SELECT 1 spring.redis.database=0 spring.redis.host=192.168.1.130 spring.redis.port=6379 -spring.redis.password=kaixin +spring.redis.password=123456 spring.redis.timeout=5000ms spring.redis.lettuce.pool.max-idle=10 spring.redis.lettuce.pool.min-idle=5 @@ -46,7 +46,7 @@ spring.mail.properties.mail.smtp.starttls.required= true # ============================== # service base URL for confirmation link # ============================== -service.url=http://192.168.1.130:9999 +service.url=http://forum.polysys.cn/ # ============================== # File upload configuration @@ -54,4 +54,4 @@ service.url=http://192.168.1.130:9999 spring.servlet.multipart.max-file-size=500KB spring.servlet.multipart.max-request-size =500KB -enable.swagger=true \ No newline at end of file +enable.swagger=false \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ee0979b..2c807f0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ server.port=9999 -spring.profiles.active= local +spring.profiles.active= pro server.servlet.context-path= / spring.aop.proxy-target-class=true # ============================== -- Gitee From 0d8113d7330359dd463b96c90b0a176c622498b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Mon, 8 Jul 2019 09:14:51 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/messages.properties | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index d1f7b6a..7ac937a 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -6,6 +6,9 @@ userForm.email.invalid=This is an invalid Email. userForm.email.duplicate=This Email already exists. userForm.password.length=Try one with at least 5 characters. userForm.password.diff=These passwords don't match. +message.badCredentials=badCredentials +auth.message.disabled=User is disabled +auth.message.expired=User account has expired # new post messages post.title.length=Title of new post must use 3 and 150 characters. post.body.length=Body of new post must use 3 and 65535 characters. -- Gitee From 97806c6eb765e091d1000f94010bc657678d4fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Mon, 8 Jul 2019 10:38:01 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fstack/constant/StorageConstant.java | 3 +-- src/main/java/com/fstack/service/impl/UserServiceImpl.java | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/fstack/constant/StorageConstant.java b/src/main/java/com/fstack/constant/StorageConstant.java index 95762f6..d53099d 100644 --- a/src/main/java/com/fstack/constant/StorageConstant.java +++ b/src/main/java/com/fstack/constant/StorageConstant.java @@ -7,8 +7,7 @@ package com.fstack.constant; */ public class StorageConstant { private StorageConstant() {} - //default avatar - public static final String DEFAULT_AVATAR_FILENAME = "default.jpg"; + //base path define public static final String BASE_DIRECTORY_NAME = "FsForumData"; diff --git a/src/main/java/com/fstack/service/impl/UserServiceImpl.java b/src/main/java/com/fstack/service/impl/UserServiceImpl.java index b0268f1..2752c14 100644 --- a/src/main/java/com/fstack/service/impl/UserServiceImpl.java +++ b/src/main/java/com/fstack/service/impl/UserServiceImpl.java @@ -59,7 +59,7 @@ public class UserServiceImpl implements UserService { @Override public int save(User user) { user.setPassword(passwordEncoder.encode(user.getPassword())); - user.setAvatarLocation(StorageConstant.DEFAULT_AVATAR_FILENAME); + user.setAvatarLocation("/avatar/admin/timg.jpg"); return userMapper.save(user); } @@ -162,9 +162,8 @@ public class UserServiceImpl implements UserService { user.setEmail(userDto.getEmail()); user.setDateCreated(new Timestamp(System.currentTimeMillis())); user.setRoles(User.USER); - if (userDto.getUsername().startsWith("IT")) user.activated(true); - else user.activated(false); - // save new user and get number of affected row + user.activated(false); + user.setAvatarLocation("/avatar/admin/timg.jpg"); int affectedRow = userMapper.save(user); // publish registration event -- Gitee From 478c27e2e667e6ae9b75812815fc58f478d07cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E?= <672943942@qq.com> Date: Mon, 8 Jul 2019 11:00:21 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fstack/service/impl/PostServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/fstack/service/impl/PostServiceImpl.java b/src/main/java/com/fstack/service/impl/PostServiceImpl.java index d9f260d..ed6c3a9 100644 --- a/src/main/java/com/fstack/service/impl/PostServiceImpl.java +++ b/src/main/java/com/fstack/service/impl/PostServiceImpl.java @@ -104,6 +104,7 @@ public class PostServiceImpl implements PostService { // find category String categoryName = newPostForm.getCategory().replace(",", ""); Category category = this.categoryMapper.findByName(categoryName); + if (null == category) category = this.categoryMapper.findByName("default"); // construct new post Post post = new Post(); post.setTitle(newPostForm.getTitle()); -- Gitee