mirror of https://github.com/halo-dev/halo
👽 代码优化
parent
8e9c4b14c3
commit
d75509918a
|
@ -40,13 +40,14 @@ public class FreeMarkerConfig {
|
|||
|
||||
@PostConstruct
|
||||
public void setSharedVariable() {
|
||||
configuration.setSharedVariable("commonTag", commonTagDirective);
|
||||
configuration.setSharedVariable("articleTag", articleTagDirective);
|
||||
try {
|
||||
//自定义标签
|
||||
configuration.setSharedVariable("commonTag", commonTagDirective);
|
||||
configuration.setSharedVariable("articleTag", articleTagDirective);
|
||||
configuration.setSharedVariable("options", optionsService.findAllOptions());
|
||||
configuration.setSharedVariable("user", userService.findUser());
|
||||
} catch (TemplateModelException e) {
|
||||
e.printStackTrace();
|
||||
log.error("自定义标签加载失败:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/16
|
||||
*/
|
||||
public enum TrueFalse {
|
||||
|
||||
/**
|
||||
* 真
|
||||
*/
|
||||
TRUE("true"),
|
||||
|
||||
/**
|
||||
* 假
|
||||
*/
|
||||
FALSE("false");
|
||||
|
||||
private String desc;
|
||||
|
||||
TrueFalse(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.enums.TrueFalse;
|
||||
import cc.ryanc.halo.repository.UserRepository;
|
||||
import cc.ryanc.halo.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -127,7 +128,7 @@ public class UserServiceImpl implements UserService {
|
|||
@Override
|
||||
public User updateUserNormal() {
|
||||
User user = this.findUser();
|
||||
user.setLoginEnable("true");
|
||||
user.setLoginEnable(TrueFalse.TRUE.getDesc());
|
||||
user.setLoginError(0);
|
||||
user.setLoginLast(new Date());
|
||||
userRepository.save(user);
|
||||
|
|
|
@ -9,6 +9,7 @@ import cc.ryanc.halo.model.dto.JsonResult;
|
|||
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.model.enums.ResultCode;
|
||||
import cc.ryanc.halo.model.enums.TrueFalse;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.LogsService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
|
@ -134,7 +135,7 @@ public class AdminController extends BaseController {
|
|||
loginLast = aUser.getLoginLast();
|
||||
}
|
||||
Long between = DateUtil.between(loginLast, DateUtil.date(), DateUnit.MINUTE);
|
||||
if (StringUtils.equals(aUser.getLoginEnable(), "false") && (between < 10)) {
|
||||
if (StringUtils.equals(aUser.getLoginEnable(), TrueFalse.FALSE.getDesc()) && (between < 10)) {
|
||||
return new JsonResult(ResultCode.FAIL.getCode(), "已禁止登录,请10分钟后再试");
|
||||
}
|
||||
//验证用户名和密码
|
||||
|
@ -158,7 +159,7 @@ public class AdminController extends BaseController {
|
|||
Integer errorCount = userService.updateUserLoginError();
|
||||
//超过五次禁用账户
|
||||
if (errorCount >= 5) {
|
||||
userService.updateUserLoginEnable("false");
|
||||
userService.updateUserLoginEnable(TrueFalse.FALSE.getDesc());
|
||||
}
|
||||
logsService.saveByLogs(
|
||||
new Logs(
|
||||
|
|
|
@ -5,6 +5,7 @@ import cc.ryanc.halo.model.domain.Logs;
|
|||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.model.enums.ResultCode;
|
||||
import cc.ryanc.halo.service.AttachmentService;
|
||||
import cc.ryanc.halo.service.LogsService;
|
||||
|
@ -91,7 +92,7 @@ public class AttachmentController {
|
|||
Page<Attachment> attachments = attachmentService.findAllAttachments(pageable);
|
||||
model.addAttribute("attachments", attachments);
|
||||
model.addAttribute("id", id);
|
||||
if (StringUtils.equals(type, "post")) {
|
||||
if (StringUtils.equals(type, PostType.POST_TYPE_POST.getDesc())) {
|
||||
return "admin/widget/_attachment-select-post";
|
||||
}
|
||||
return "admin/widget/_attachment-select";
|
||||
|
@ -206,8 +207,8 @@ public class AttachmentController {
|
|||
* 移除附件的请求
|
||||
*
|
||||
* @param attachId 附件编号
|
||||
* @param request request
|
||||
* @return true:移除附件成功,false:移除附件失败
|
||||
* @param request request
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
@ResponseBody
|
||||
|
|
|
@ -5,8 +5,10 @@ import cc.ryanc.halo.model.domain.User;
|
|||
import cc.ryanc.halo.model.dto.BackupDto;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.model.enums.ResultCode;
|
||||
import cc.ryanc.halo.model.enums.TrueFalse;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
|
@ -201,7 +203,7 @@ public class BackupController {
|
|||
if (null == user.getUserEmail() || StringUtils.equals(user.getUserEmail(), "")) {
|
||||
return new JsonResult(ResultCode.FAIL.getCode(), "博主邮箱没有配置!");
|
||||
}
|
||||
if (StringUtils.equals(HaloConst.OPTIONS.get("smtp_email_enable"), "false")) {
|
||||
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), TrueFalse.FALSE.getDesc())) {
|
||||
return new JsonResult(ResultCode.FAIL.getCode(), "发信邮箱没有配置!");
|
||||
}
|
||||
new EmailToAdmin(srcPath, user).start();
|
||||
|
|
|
@ -7,6 +7,7 @@ import cc.ryanc.halo.model.dto.HaloConst;
|
|||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.CommentStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.model.enums.TrueFalse;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
|
@ -120,7 +121,7 @@ public class CommentController extends BaseController {
|
|||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
|
||||
//判断是否启用邮件服务
|
||||
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), "true") && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.COMMENT_REPLY_NOTICE.getProp()), "true")) {
|
||||
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), TrueFalse.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.COMMENT_REPLY_NOTICE.getProp()), TrueFalse.TRUE.getDesc())) {
|
||||
try {
|
||||
if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
@ -211,7 +212,7 @@ public class CommentController extends BaseController {
|
|||
commentService.saveByComment(comment);
|
||||
|
||||
//邮件通知
|
||||
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), "true") && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.COMMENT_REPLY_NOTICE.getProp()), "true")) {
|
||||
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), TrueFalse.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.COMMENT_REPLY_NOTICE.getProp()), TrueFalse.TRUE.getDesc())) {
|
||||
if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("blogTitle", HaloConst.OPTIONS.get(BlogProperties.BLOG_TITLE.getProp()));
|
||||
|
|
|
@ -41,7 +41,7 @@ public class OptionController {
|
|||
* 保存设置选项
|
||||
*
|
||||
* @param options options
|
||||
* @return true:保存成功,false:保存失败
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/save")
|
||||
@ResponseBody
|
||||
|
|
|
@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.*;
|
|||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.TrueFalse;
|
||||
import cc.ryanc.halo.service.*;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
|
@ -63,7 +64,7 @@ public class InstallController {
|
|||
@GetMapping
|
||||
public String install(Model model) {
|
||||
try {
|
||||
if (StringUtils.equals("true", HaloConst.OPTIONS.get(BlogProperties.IS_INSTALL.getProp()))) {
|
||||
if (StringUtils.equals(TrueFalse.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogProperties.IS_INSTALL.getProp()))) {
|
||||
model.addAttribute("isInstall", true);
|
||||
} else {
|
||||
model.addAttribute("isInstall", false);
|
||||
|
@ -96,7 +97,7 @@ public class InstallController {
|
|||
@RequestParam("userPwd") String userPwd,
|
||||
HttpServletRequest request) {
|
||||
try {
|
||||
if (StringUtils.equals("true", HaloConst.OPTIONS.get(BlogProperties.IS_INSTALL.getProp()))) {
|
||||
if (StringUtils.equals(TrueFalse.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogProperties.IS_INSTALL.getProp()))) {
|
||||
return false;
|
||||
}
|
||||
//创建新的用户
|
||||
|
@ -148,7 +149,7 @@ public class InstallController {
|
|||
comment.setIsAdmin(0);
|
||||
commentService.saveByComment(comment);
|
||||
|
||||
optionsService.saveOption(BlogProperties.IS_INSTALL.getProp(), "true");
|
||||
optionsService.saveOption(BlogProperties.IS_INSTALL.getProp(), TrueFalse.TRUE.getDesc());
|
||||
|
||||
//保存博客标题和博客地址设置
|
||||
optionsService.saveOption(BlogProperties.BLOG_TITLE.getProp(), blogTitle);
|
||||
|
@ -164,12 +165,12 @@ public class InstallController {
|
|||
optionsService.saveOption(BlogProperties.COMMENT_SYSTEM.getProp(), "native");
|
||||
|
||||
//默认不配置邮件系统
|
||||
optionsService.saveOption(BlogProperties.SMTP_EMAIL_ENABLE.getProp(), "false");
|
||||
optionsService.saveOption(BlogProperties.SMTP_EMAIL_ENABLE.getProp(), TrueFalse.FALSE.getDesc());
|
||||
|
||||
//新评论,审核通过,回复,默认不通知
|
||||
optionsService.saveOption(BlogProperties.NEW_COMMENT_NOTICE.getProp(), "false");
|
||||
optionsService.saveOption(BlogProperties.COMMENT_PASS_NOTICE.getProp(), "false");
|
||||
optionsService.saveOption(BlogProperties.COMMENT_REPLY_NOTICE.getProp(), "false");
|
||||
optionsService.saveOption(BlogProperties.NEW_COMMENT_NOTICE.getProp(), TrueFalse.FALSE.getDesc());
|
||||
optionsService.saveOption(BlogProperties.COMMENT_PASS_NOTICE.getProp(), TrueFalse.FALSE.getDesc());
|
||||
optionsService.saveOption(BlogProperties.COMMENT_REPLY_NOTICE.getProp(), TrueFalse.FALSE.getDesc());
|
||||
|
||||
//更新日志
|
||||
logsService.saveByLogs(
|
||||
|
|
|
@ -4,10 +4,7 @@ import cc.ryanc.halo.model.domain.Comment;
|
|||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.CommentStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.model.enums.ResultCode;
|
||||
import cc.ryanc.halo.model.enums.*;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
|
@ -153,7 +150,7 @@ public class FrontCommentController {
|
|||
}
|
||||
@Override
|
||||
public void run(){
|
||||
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), "true") && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NOTICE.getProp()), "true")) {
|
||||
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), TrueFalse.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NOTICE.getProp()), TrueFalse.TRUE.getDesc())) {
|
||||
try {
|
||||
//发送邮件到博主
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
@ -191,7 +188,7 @@ public class FrontCommentController {
|
|||
@Override
|
||||
public void run() {
|
||||
//发送通知给对方
|
||||
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), "true") && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NOTICE.getProp()), "true")) {
|
||||
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), TrueFalse.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NOTICE.getProp()), TrueFalse.TRUE.getDesc())) {
|
||||
if(Validator.isEmail(lastComment.getCommentAuthorEmail())){
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("blogTitle",HaloConst.OPTIONS.get(BlogProperties.BLOG_TITLE.getProp()));
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.interceptor;
|
|||
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.TrueFalse;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
@ -18,7 +19,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
public class ApiInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
if (StringUtils.equals("true", HaloConst.OPTIONS.get(BlogProperties.API_STATUS.getProp()))) {
|
||||
if (StringUtils.equals(TrueFalse.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogProperties.API_STATUS.getProp()))) {
|
||||
return true;
|
||||
}
|
||||
response.sendRedirect("/404");
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.interceptor;
|
|||
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.TrueFalse;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
@ -19,7 +20,7 @@ public class InstallInterceptor implements HandlerInterceptor {
|
|||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
|
||||
if (StringUtils.equals("true", HaloConst.OPTIONS.get(BlogProperties.IS_INSTALL.getProp()))) {
|
||||
if (StringUtils.equals(TrueFalse.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogProperties.IS_INSTALL.getProp()))) {
|
||||
return true;
|
||||
}
|
||||
response.sendRedirect("/install");
|
||||
|
|
Loading…
Reference in New Issue